﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.CreditCard;
using CE.User;
using CE.PostCode;
using CE.CarInsurance;
using CE.Provider;
using CE.Security;
using CE.StreetDirectory;

public partial class car_Insurance_new_proposalforms_etiqa_proposal_form : System.Web.UI.Page
{
    public static Int64 _CarId, _CarMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;
    protected void Page_Load(object sender, EventArgs e)
    {
        //string isCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsCXLive").ToString();
        ///<summary>
        ///Teledirect Agent's Telemarketing (UserTypeId = SiteUser(200))
        ///Request.Params["uid"] - Email Address to retrieve CEID
        ///Request.Params["guid"] - Table tblCEUser's rowguid to check user request validation
        ///Request.Params["carid"] - Customer's Car Id
        ///Request.Params["carresultid"] - Customer's Car Result Id (Will be selected by Agent)
        ///Request.Params["providercompanyid"] -  Selected Result Item's ProviderCompanyId to validate proposal form
        ///</summary>
        if (Request.Params["uid"] != null && Request.Params["guid"] != null && Request.Params["carid"] != null
            && Request.Params["customerid"] != null && Request.Params["carresultid"] != null && Request.Params["providercompanyid"] != null)
        {
            lblProviderCompanyId.Text = Request.Params["providercompanyid"].ToString();
            if (lblProviderCompanyId.Text != "30")
            {
                Response.Redirect("~/");
            }
            else
            {
                if (!CheckAgentRequest(Request.Params["uid"].ToString(), Request.Params["guid"].ToString(), Request.Params["customerid"].ToString(), Request.Params["carid"].ToString(), Request.Params["carresultid"].ToString()))
                {
                    Response.Redirect("~/");
                }
              
            }
        }
        else
        {
            if (Session[General.AgentId] != null)
            {
                divAgent.Visible = true;
                lblAgentName.Text = Session[General.AgentName].ToString();
            }
            else
            {
                divAgent.Visible = false;
            }
            if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
            {
                if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
                     Convert.ToInt32(CE.Global.CEUserType.Customer) && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
                     Convert.ToInt32(CE.Global.CEUserType.Provider))
                {
                    Response.Redirect("~/car-insurance/login.aspx");
                }
            }
            else
            {
                Response.Redirect("~/car-insurance/login.aspx");
            }

            if (Session[General.CarId] == null || Session[General.CarPolicyId] == null)
            {
                Response.Redirect("~/car-insurance/profile.aspx");
            }

            if (Session[CE.Global.General.CarResultId] != null)
            {
                if (Session[General.ProviderCompanyId].ToString() != "30")
                {
                    Response.Redirect("~/user/viewresulthistory.aspx");
                }
            }
            else
            {
                Response.Redirect("~/user/viewresulthistory.aspx");
            }

        }

       
       

        if (!IsPostBack)
        {
            lblDisclaimer.Text = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaCarProposalDisclaimer");
            lblDisclaimer.Text += "<br/><br/>";
            lblDisclaimer.Text += "An additional excess of $4000 will be imposed on top of the policy excess if vehicle is driven by any authorized person who is below 27 years of age or has less than 2 yrs of driving experience.";
            lblDisclaimer.Text += "<br/><br/>";
            lblDisclaimer.Text += "<b>Policy Owners’ Protection Scheme</b> <br/>";
            lblDisclaimer.Text += "This policy is protected under the Policy Owners’ Protection Scheme which is administered by the Singapore Deposit Insurance ";
            lblDisclaimer.Text += "Corporation (SDIC). Coverage for your policy is automatic and no further action is required from you. For more information on the types of benefits ";
            lblDisclaimer.Text += "that are covered under the scheme as well as the limits of coverage, where applicable, please contact your insurer or visit the GIA / LIA or SDIC ";
            lblDisclaimer.Text += "websites (<a href='http://www.gia.org.sg' target='_blank' >www.gia.org.sg</a> or <a href='http://www.lia.org.sg' target='_blank'>www.lia.org.sg</a> or <a href='http://www.sdic.org.sg' target='_blank'>www.sdic.org.sg</a>).";

            #region Date Start & End

            ddlDOCancellation.StartYear = CE.Global.General.GetUTCDateTime().Year;
            ddlDOCancellation.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;

            #endregion

            #region Load Combo

            InsurerDB _insurerdb = new InsurerDB();
            DataTable dtPreInsurerComp = _insurerdb.GetPreInsurer(100, 1);
            ddlExistingInsurerName.DataSource = dtPreInsurerComp;
            ddlExistingInsurerName.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
            ddlExistingInsurerName.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
            ddlExistingInsurerName.DataBind();
            ddlExistingInsurerName.Items.Insert(0, new ListItem("Select", "-1"));

            DataTable dtPreInsurerBank = _insurerdb.GetPreInsurer(100, 2);
            ddlHirePurchaseCompany.DataSource = dtPreInsurerBank;
            ddlHirePurchaseCompany.DataTextField = dtPreInsurerBank.Columns[0].ColumnName.ToString();
            ddlHirePurchaseCompany.DataValueField = dtPreInsurerBank.Columns[1].ColumnName.ToString();
            ddlHirePurchaseCompany.DataBind();
            ddlHirePurchaseCompany.Items.Insert(0, new ListItem("Select", "-1"));

            #endregion

            #region Validation Effect

            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "')");
            txtPostCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostCode.ClientID + "','" + rfvPostCode.ClientID + "','" + revPostCode.ClientID + "')");
            txtUnit1.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit1.ClientID + "','" + rfvUnit1.ClientID + "')");
            txtUnit2.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit2.ClientID + "','" + rfvUnit2.ClientID + "')");
            txtAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtAddress.ClientID + "','" + rfvAddress.ClientID + "')");
            txtVehicleNo.Attributes.Add("onblur", "ShowValidationEffect('" + txtVehicleNo.ClientID + "','" + rfvVehicleNo.ClientID + "')");
            txtEngineNo.Attributes.Add("onblur", "ShowValidationEffect('" + txtEngineNo.ClientID + "','" + rfvEngineNo.ClientID + "')");
            txtChassisNo.Attributes.Add("onblur", "ShowValidationEffect('" + txtChassisNo.ClientID + "','" + rfvChassisNo.ClientID + "')");
            ddlHirePurchaseCompany.Attributes.Add("onblur", "ShowValidationEffect('" + ddlHirePurchaseCompany.ClientID + "','" + rfvHirePurchaseCompany.ClientID + "')");
            ddlExistingInsurerName.Attributes.Add("onblur", "ShowValidationEffect('" + ddlExistingInsurerName.ClientID + "','" + rfvExistingInsurerName.ClientID + "')");
            txtInsPolicyNo.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsPolicyNo.ClientID + "','" + rfvInsPolicyNo.ClientID + "')");
            txtDrivername1.Attributes.Add("onblur", "ShowValidationEffect('" + txtDrivername1.ClientID + "','" + rfvDrivername1.ClientID + "')");
            txtTotalpoints1.Attributes.Add("onblur", "ShowValidationEffect('" + txtTotalpoints1.ClientID + "','" + rfvTotalpoints1.ClientID + "')");
            txtPIReason.Attributes.Add("onblur", "ShowValidationEffect('" + txtPIReason.ClientID + "','" + rfvPIReason.ClientID + "')");
            txtITReason.Attributes.Add("onblur", "ShowValidationEffect('" + txtITReason.ClientID + "','" + rfvITReason.ClientID + "')");

            txtDriverSurName1.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName1.ClientID + "','" + rfvDriverSurName1.ClientID + "')");
            txtDriverSurName2.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName2.ClientID + "','" + rfvDriverSurName2.ClientID + "')");
            txtDriverSurName3.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName3.ClientID + "','" + rfvDriverSurName3.ClientID + "')");
            txtDriverSurName4.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName4.ClientID + "','" + rfvDriverSurName4.ClientID + "')");
            txtDriverSurName5.Attributes.Add("onblur", "ShowValidationEffect('" + txtDriverSurName5.ClientID + "','" + rfvDriverSurName5.ClientID + "')");

            //rdoYesHirePurchase.Attributes.Add("onblur", "CheckHirePurchaseValidationCss();");
            //rdoNoHirePurchase.Attributes.Add("onblur", "CheckHirePurchaseValidationCss();");
            //rdoYesExistingInsurer.Attributes.Add("onblur", "CheckExistingInsurerValidationCss();");
            //rdoNoExistingInsurer.Attributes.Add("onblur", "CheckExistingInsurerValidationCss();");
            //rdoYesDermeritPoints.Attributes.Add("onblur", "CheckDermeritPointsValidationCss();");
            //rdoNoDermeritPoints.Attributes.Add("onblur", "CheckDermeritPointsValidationCss();");
            //rdoYesPhysicalimpairment.Attributes.Add("onblur", "CheckPhysicalimpairmentValidationCss();");
            //rdoNoPhysicalimpairment.Attributes.Add("onblur", "CheckPhysicalimpairmentValidationCss();");
            //rdoYesInsuranceterminated.Attributes.Add("onblur", "CheckInsuranceterminatedValidationCss();");
            //rdoNoInsuranceterminated.Attributes.Add("onblur", "CheckInsuranceterminatedValidationCss();");
            //rdoVisa.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            //rdoMasterCard.Attributes.Add("onblur", "CheckCardTypeValidationCss();");

            #endregion

            #region Set Property
            if (Session[CE.Global.General.UserPhoneNo] != null && Session[CE.Global.General.UserName] != null)
            {
                txtContactNo.PhoneNo = Session[CE.Global.General.UserPhoneNo].ToString();
                txtName.Text = Session[CE.Global.General.UserName].ToString();
            }
            else if (lblCustomerId.Text != string.Empty)
            {
                txtName.Text = lblCustomerGivenName.Text;
                txtContactNo.PhoneNo = lblCustomerMobileNo.Text;
            }

            LoadCarPolicyDetails();

            if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
            {
                _CarId = Convert.ToInt64(lblCarId.Text);
                _UserId = Convert.ToInt64(lblCustomerId.Text);
                _CXCTypeId = Convert.ToInt64(lblCarResultId.Text);
                _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
            }
            else
            {
                _CarId = Convert.ToInt64(Session[General.CarId].ToString());
                _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
                _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
            }

            MyDatabase _db = new MyDatabase();
            string _strSql = "SELECT COUNT(CECarMoreDetailId) FROM [tblCarMoreDetail_Etiqa] WHERE CECarId = " + _CarId.ToString() + " And RefCEUserId = " + _UserId.ToString();
            object _count = _db.ExecuteScalarSqlStatement(_strSql);

            if (Convert.ToInt32(_count) > 0)
            {
                ShowCarMoreDetail(_CarId, _UserId);
            }
            else
            {
                lblCarMoreDetailId.Text = "0";
                Session[General.CarMoreDetailId] = "0";
            }
            #endregion


            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            GetNCDProtection();

            //lnkBackTop.HRef = Request.UrlReferrer.ToString();
            //lnkBackBottom.HRef = Request.UrlReferrer.ToString();

            if (Request.Params["uid"] != null && Request.Params["guid"] != null && Request.Params["carid"] != null
           && Request.Params["customerid"] != null && Request.Params["carresultid"] != null && Request.Params["providercompanyid"] != null)
            {
                divAgentSave.Visible = true;

                //check for saved details
                EtiqaCarMoreDetail _etiqasavedetails = new EtiqaCarMoreDetail();
                EtiqaCarMoreDetailDB _etiqadb = new EtiqaCarMoreDetailDB();

                _etiqasavedetails = _etiqadb.GetCarMoreDetail(_CarId, _UserId);

                if (_etiqasavedetails != null)
                {
                    LoadSavedDetails();
                }
            }

            if (Session[General.AgentId] != null)
            {
                divAgentSave.Visible = true;

                //check for saved details
                EtiqaCarMoreDetail _etiqasavedetails = new EtiqaCarMoreDetail();
                EtiqaCarMoreDetailDB _etiqadb = new EtiqaCarMoreDetailDB();

                _etiqasavedetails = _etiqadb.GetCarMoreDetail(_CarId, _UserId);

                if (_etiqasavedetails != null)
                {
                    LoadSavedDetails();
                }
            }

        }
        //if (rdoYesExistingInsurer.Checked || rdoNoExistingInsurer.Checked) txtExistingInsurer.Text = "1";
        if (rdoYesDermeritPoints.Checked || rdoNoDermeritPoints.Checked) txtDermeritPoints.Text = "1";
        if (rdoYesPhysicalimpairment.Checked || rdoNoPhysicalimpairment.Checked) txtPhysicalimpairment.Text = "1";
        if (rdoYesInsuranceterminated.Checked || rdoNoInsuranceterminated.Checked) txtInsuranceterminated.Text = "1";
        if (rdoYesHirePurchase.Checked || rdoNoHirePurchase.Checked) txtHirePurchase.Text = "1";
    }

    private bool CheckAgentRequest(string AgentId, string GUID, string CustomerId, string CarId, string CarResultId)
    {
        bool _retVal = false;
        try
        {
            lblAgentId.Text = string.Empty;
            lblCustomerId.Text = string.Empty;
            lblCustomerGivenName.Text = string.Empty;
            lblCustomerMobileNo.Text = string.Empty;
            lblCarId.Text = string.Empty;
            lblCarResultId.Text = string.Empty;

            Account _account = new Account();
            AccountDB _accountdb = new AccountDB();
            _account = _accountdb.CheckEmail(AgentId, 200);
            if (_account != null)
            {
                string _guid = _accountdb.GetGUID(_account.CEID);
                if (GUID.ToUpper() == _guid.ToUpper())
                {
                    lblAgentId.Text = _account.CEID.ToString();
                    if (!CheckSelectedStatus(CustomerId, CarId))
                    {
                        MyDatabase _db = new MyDatabase();
                        DataTable _dtResult = new DataTable();
                        string _spName = "[sprocCarInsuranceResultSelectSingleItem]";
                        SortedList _sPara = new SortedList();
                        _sPara.Add("@CECarId", Convert.ToInt64(CarId));
                        _sPara.Add("@RefCEUserId", Convert.ToInt64(CustomerId));
                        _sPara.Add("@CarResultId", Convert.ToInt64(CarResultId));
                        _dtResult = _db.GetDataTableBySP(_spName, _sPara);
                        if (_dtResult != null && _dtResult.Rows.Count == 1)
                        {
                            lblCustomerId.Text = CustomerId;
                            lblCarResultId.Text = CarResultId.ToString();
                            lblCarId.Text = CarId;
                            Profile _profile = new Profile();
                            ProfileDB _profiledb = new ProfileDB();
                            _profile = _profiledb.GetProfile(Convert.ToInt64(CustomerId));
                            if (_profile != null)
                            {
                                lblCustomerGivenName.Text = _profile.SurName;
                                if (_profile.FirstName.Length > 0)
                                {
                                    lblCustomerGivenName.Text += " " + _profile.FirstName;
                                }
                            }

                            Contact _contact = new Contact();
                            ContactDB _contactdb = new ContactDB();
                            _contact = _contactdb.GetContact(Convert.ToInt64(CustomerId));
                            if (_contact != null)
                            {
                                lblCustomerMobileNo.Text = _contact.Mobile;
                            }

                            _profile = null;
                            _profiledb = null;
                            _contact = null;
                            _contactdb = null;
                            _dtResult = null;
                            _db = null;
                            _retVal = true;
                        }
                        else
                        {
                            _retVal = false;
                        }
                    }
                }
                else
                {
                    _retVal = false;
                }
            }
            else
            {
                _retVal = false;
            }
        }
        catch (Exception Ex)
        {
            _retVal = false;
        }
        return _retVal;
    }

    private bool CheckSelectedStatus(string CustomerId, string CarId)
    {
        MyDatabase _db = new MyDatabase();
        string _strSQLCheckSelected = "select COUNT(CISelectItemId) from tblCarInsuranceSelectItem Where Status = 1 And RefCEUserId = " + CustomerId + " And CECarId = " + CarId;
        object _objSelectStatus = _db.ExecuteScalarSqlStatement(_strSQLCheckSelected);

        bool _IsSelected = false;
        if (_objSelectStatus != null)
        {
            _IsSelected = Convert.ToInt32(_objSelectStatus) > 0;
        }
        _db = null;
        return _IsSelected;
    }
    
    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0 && _dt.Columns.Count >= 2)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";
                                
                                if (_dr["t"] != null && _dr["a"] != null)
                                {
                                    _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                    _lstText = _dr["t"].ToString();
                                    ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                    if (_rowCount == 0)
                                    {
                                        txtAddress.Text = _lstValue;
                                        //ibtPostCode.Enabled = false;
                                        txtAddress.ReadOnly = true;
                                    }

                                    _rowCount++;
                                }
                            }
                        }
                        else
                        {
                            txtAddress.Text = "Confirm postcode or enter manually.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "Confirm postcode or enter manually.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        CheckValidation();
        ChangeValidationEffectServerSide("proposal");

        if (IsValid)
        {
            if (rdoYesModifiedVehicle.Checked == true)
            {
                vsproposal.Visible = true;
                vsproposal.HeaderText = "Sorry, Etiqa declines modified/altered vehicles.";
            }
            else
            {
                if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty
                    && lblCarResultId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
                {
                    _CarId = Convert.ToInt64(lblCarId.Text);
                    _UserId = Convert.ToInt64(lblCustomerId.Text);
                    _CXCTypeId = Convert.ToInt64(lblCarResultId.Text);
                    _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
                    _CarMoreId = Convert.ToInt64(lblCarMoreDetailId.Text);
                    _AgentId = Convert.ToInt64(lblAgentId.Text);
                }
                else if (Session[General.CarId] != null && Session[General.UserId] != null
                    && Session[General.CarResultId] != null && Session[General.ProviderCompanyId] != null)
                {
                    _CarId = Convert.ToInt64(Session[General.CarId].ToString());
                    _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                    _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
                    _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
                    _CarMoreId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());

                    if (Session[General.AgentId] != null)
                    {
                        _AgentId = Convert.ToInt64(Session[General.AgentId].ToString());
                    }
                    else
                    {
                        _AgentId = 0;
                    }
                }
                Int64 _carmoreresult = 0;
                Int64 demeritresult = 0;
                Int64 driverresult = 0;

                //Session[CE.Global.General.CvvId] = null;
                EtiqaCarMoreDetail _etiqacarmoredetail = new EtiqaCarMoreDetail();
                EtiqaCarMoreDetailDB _etiqacarmoredetaildb = new EtiqaCarMoreDetailDB();

                _etiqacarmoredetail.NInfo1 = _AgentId;
                //if (Session[General.CarMoreDetailId] != null)
                //{
                //    _etiqacarmoredetail.CECarMoreDetailId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());
                //}
                //else
                //{
                //    _etiqacarmoredetail.CECarMoreDetailId = 0;
                //}

                _etiqacarmoredetail.CECarId = _CarId;
                _etiqacarmoredetail.ProviderCompanyId = _ProviderId;
                _etiqacarmoredetail.Name = txtName.Text.ToUpper();
                _etiqacarmoredetail.PostalCode = txtPostCode.Text.Trim();
                _etiqacarmoredetail.UnitNo = txtUnit1.Text.Trim();
                _etiqacarmoredetail.HomeNo = txtUnit2.Text.Trim();
                _etiqacarmoredetail.Address = txtAddress.Text.Trim();
                _etiqacarmoredetail.ContactNo = txtContactNo.GetPhoneNo();
                _etiqacarmoredetail.NRICNo = ddlIdNumber.GetIdNumber();
                _etiqacarmoredetail.Nationality = ddlNationality.GetNationality();
                _etiqacarmoredetail.VechicleNo = txtVehicleNo.Text.Trim();
                _etiqacarmoredetail.EngineNo = txtEngineNo.Text.Trim();
                _etiqacarmoredetail.ChassisNo = txtChassisNo.Text.Trim();
                _etiqacarmoredetail.HasHirePurchase = rdoYesHirePurchase.Checked;
                if (rdoYesHirePurchase.Checked == true)
                {
                    _etiqacarmoredetail.HPCompanyName = ddlHirePurchaseCompany.Text;
                }
                else
                {
                    _etiqacarmoredetail.HPCompanyName = "";
                }
                _etiqacarmoredetail.HasPreInsurer = true; // rdoYesExistingInsurer.Checked;
                //if (rdoYesExistingInsurer.Checked == true)
                if (ddlExistingInsurerName.Text != "177")
                {
                    _etiqacarmoredetail.PreInsurerName = ddlExistingInsurerName.Text;
                    _etiqacarmoredetail.PreInsPolicyNo = txtInsPolicyNo.Text.Trim();
                    _etiqacarmoredetail.PreInsExpiryDate = ddlDOCancellation.GetDate();
                }
                else
                {
                    _etiqacarmoredetail.PreInsurerName = ddlExistingInsurerName.Text;
                    _etiqacarmoredetail.PreInsPolicyNo = "";
                    _etiqacarmoredetail.PreInsExpiryDate = Convert.ToDateTime("1900-01-01 00:00:00.000");
                }
                _etiqacarmoredetail.HasDemeritPoints = rdoYesDermeritPoints.Checked;

                _etiqacarmoredetail.HasInsuranceTerminated = rdoYesInsuranceterminated.Checked;
                if (rdoYesInsuranceterminated.Checked == true)
                {
                    _etiqacarmoredetail.InsuranceTerminatedReason = txtITReason.Text.Trim();
                }
                else
                {
                    _etiqacarmoredetail.InsuranceTerminatedReason = "";
                }
                _etiqacarmoredetail.HasPhysicalImpairment = rdoYesPhysicalimpairment.Checked;
                if (rdoYesPhysicalimpairment.Checked == true)
                {
                    _etiqacarmoredetail.PhysicalImpairmentReason = txtPIReason.Text.Trim();
                }
                else
                {
                    _etiqacarmoredetail.PhysicalImpairmentReason = "";
                }

                string _totalPaymentAmount = "";
                string _paymentOrderNo = "";
                string val = GetOrderNumber();
                string[] _orderno = val.Split(',');
                _etiqacarmoredetail.OrderNo = _orderno[0].ToString();
                _paymentOrderNo = _orderno[0].ToString();
                _etiqacarmoredetail.OrderSerialNo = Convert.ToInt64(_orderno[1].ToString());

                //_etiqacarmoredetail.PaymentStatus = false;
                _etiqacarmoredetail.QuoteRefNo = lblQRefNo.Text.Trim();

                _etiqacarmoredetail.RefCEUserId = _UserId;
                _etiqacarmoredetail.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _etiqacarmoredetail.Status = true;
                _etiqacarmoredetail.CarResultId = _CXCTypeId;
                if (rdoNo.Checked == false && rdoYes.Checked == false)
                {
                    _etiqacarmoredetail.Info1 = "0";
                    _totalPaymentAmount = lblPremiumBeforeNCDProNoFormat.Text;
                }
                else if (rdoNo.Checked == true && rdoYes.Checked == false)
                {
                    _etiqacarmoredetail.Info1 = "0";
                    _totalPaymentAmount = lblPremiumBeforeNCDProNoFormat.Text;
                }
                if (rdoNo.Checked == false && rdoYes.Checked == true)
                {
                    _etiqacarmoredetail.Info1 = "1";
                    _totalPaymentAmount = lblPremiumAfterNCDProNoFormat.Text;
                }

                EtiqaCarMoreDetail _etiqacarmoredetailCheck = new EtiqaCarMoreDetail();
                _etiqacarmoredetailCheck = _etiqacarmoredetaildb.GetCarMoreDetail(_CarId, _UserId);

                if (_etiqacarmoredetailCheck != null) //existing
                {
                    _etiqacarmoredetail.CECarMoreDetailId = _etiqacarmoredetailCheck.CECarMoreDetailId;
                }
                else
                {
                    _etiqacarmoredetail.CECarMoreDetailId = _CarMoreId;
                }

                _carmoreresult = _etiqacarmoredetaildb.Insert(_etiqacarmoredetail);

                if (_carmoreresult > 0)
                {
                    if (Session[General.CarId] != null && Session[General.UserId] != null
                        && Session[General.ProviderCompanyId] != null)
                    {
                        Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                    }
                    else if (lblCarId.Text != string.Empty && lblCustomerId.Text != null
                        && lblProviderCompanyId.Text != string.Empty)
                    {
                        lblCarMoreDetailId.Text = _carmoreresult.ToString();
                    }
                    //_etiqacarmoredetail.CECarMoreDetailId = Convert.ToInt64(Session[CE.Global.General.CarMoreDetailId].ToString());
                    //_etiqacarmoredetail.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                    //_etiqacarmoredetail.CarResultId = Convert.ToInt64(Session[General.CarResultId].ToString());
                    //selectresult = _etiqacarmoredetaildb.InsertUpdateSelectStatus(_etiqacarmoredetail);
                    //if (selectresult > 0)
                    //{
                    if (rdoYesDermeritPoints.Checked == true)
                    {
                        //Int64 CarId = Convert.ToInt64(Session[General.CarId].ToString());
                        //Int64 CEId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                        CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
                        _cardriverdemeritpointsdb.DeleteCarDriverDemeritPoints(_CarId, _carmoreresult, _UserId);
                        _cardriverdemeritpointsdb = null;

                        if (!SaveDemeritPoints())
                        {
                            lblMessage.Text = "Demerits failed to save!";
                        }
                        else
                        {
                            demeritresult = 1;
                        }
                    }
                    else
                    {
                        demeritresult = 1;
                    }
                    //}

                    if (demeritresult > 0)
                    {

                        if (txtDriverCount.Text.Trim() != "0")
                        {
                            if (!UpdateDriverDetails())
                            {
                                lblMessage.Text = "Car Drivers failed to save!";
                            }
                            else
                            {
                                driverresult = 1;
                            }
                        }
                        else
                        {
                            driverresult = 1;
                        }
                        if (driverresult > 0)
                        {
                            //ProposalNotification();
                            //Int64 _statusresult = 0;
                            //_etiqacarmoredetail.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
                            //_etiqacarmoredetail.CarResultId = Convert.ToInt64(Session[General.CarResultId].ToString());

                            //_statusresult = _etiqacarmoredetaildb.UpdateStatus(_etiqacarmoredetail);

                            //Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
                            //UserConfirmation _userconfirm = new UserConfirmation();
                            //UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                            //_userconfirm.ConfirmationType = "CI";
                            //_userconfirm.CurrentStep = 4;
                            ////_userconfirm.UserResultId = Convert.ToInt64(Session[General.CarResultId].ToString());
                            //_userconfirm.UserSelectedId = Convert.ToInt64(Session[General.CarResultId].ToString());
                            //_userconfirm.FirstStepId = Convert.ToInt64(Session[General.CarId].ToString());
                            //_userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                            //_userconfirm.IsConfirm = true;
                            //_userconfirm.ResultStatus = "Complete";
                            //_userconfirm.IsComplete = true;
                            //Int64 _result = _userconfirmdb.Insert(_userconfirm);
                            //if ((_result > 0) && (_statusresult > 0))
                            //{
                            //    string _provideid = Encode(Session[General.ProviderCompanyId].ToString());
                            //    General.ClearAllSession(this.Page, "ALL");
                            //    Response.Redirect("UserMessage.aspx?pcid=" + _provideid);
                            //}
                            //else
                            //{
                            //    lblMessage.Text = "Can't update confirmation status.";
                            //}

                            //Response.Redirect("purchase.aspx");
                            //Response.Redirect("https://baksvr.i2pay.com.sg/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount);
                            General.ClearAllSession(this.Page, "ALL");
                            //Response.Redirect("../etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
                            //Response.Redirect("~/personal-accident/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");

                            Response.Redirect("https://nera.i2pay.com.sg/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");

                            //Response.Redirect("~/car_insurance/etiqa/paymentmsg.aspx?ordernumber=" + _etiqacarmoredetail.OrderNo + "&email=" + _etiqacarmoredetail.CCHEmail);
                        }
                    }
                }
            }
        }
    }

    protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
    {
        CheckValidationSave();
        ChangeValidationEffectServerSideSave("tempsaveproposal");

        if (IsValid)
        {
            if (rdoYesModifiedVehicle.Checked == true)
            {
                vsproposal.Visible = true;
                vsproposal.HeaderText = "Sorry, Etiqa declines modified/altered vehicles.";
            }
            else
            {
                if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty
                       && lblCarResultId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
                {
                    _CarId = Convert.ToInt64(lblCarId.Text);
                    _UserId = Convert.ToInt64(lblCustomerId.Text);
                    _CXCTypeId = Convert.ToInt64(lblCarResultId.Text);
                    _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
                    _CarMoreId = Convert.ToInt64(lblCarMoreDetailId.Text);
                    _AgentId = Convert.ToInt64(lblAgentId.Text);
                }
                else if (Session[General.CarId] != null && Session[General.UserId] != null
                       && Session[General.CarResultId] != null && Session[General.ProviderCompanyId] != null)
                {
                    _CarId = Convert.ToInt64(Session[General.CarId].ToString());
                    _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                    _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
                    _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
                    _CarMoreId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());

                    if (Session[General.AgentId] != null)
                    {
                        _AgentId = Convert.ToInt64(Session[General.AgentId].ToString());
                    }
                    else
                    {
                        _AgentId = 0;
                    }
                }

                Int64 _carmoreresult = 0;
                Int64 demeritresult = 0;
                Int64 driverresult = 0;

                //Session[CE.Global.General.CvvId] = null;
                EtiqaCarMoreDetail _etiqacarmoredetail = new EtiqaCarMoreDetail();
                EtiqaCarMoreDetail _etiqacarmoredetailCheck = new EtiqaCarMoreDetail();
                EtiqaCarMoreDetailDB _etiqacarmoredetaildb = new EtiqaCarMoreDetailDB();

                //_etiqacarmoredetail.CECarMoreDetailId = _CarMoreId;
                _etiqacarmoredetail.NInfo1 = _AgentId;

                _etiqacarmoredetail.CECarId = _CarId;
                _etiqacarmoredetail.ProviderCompanyId = _ProviderId;
                _etiqacarmoredetail.Name = txtName.Text.ToUpper();
                _etiqacarmoredetail.PostalCode = txtPostCode.Text.Trim();
                _etiqacarmoredetail.UnitNo = txtUnit1.Text.Trim();
                _etiqacarmoredetail.HomeNo = txtUnit2.Text.Trim();
                _etiqacarmoredetail.Address = txtAddress.Text.Trim();
                _etiqacarmoredetail.ContactNo = txtContactNo.GetPhoneNo();
                _etiqacarmoredetail.NRICNo = ddlIdNumber.GetIdNumber();
                _etiqacarmoredetail.Nationality = ddlNationality.GetNationality();
                _etiqacarmoredetail.VechicleNo = txtVehicleNo.Text.Trim();
                _etiqacarmoredetail.EngineNo = txtEngineNo.Text.Trim();
                _etiqacarmoredetail.ChassisNo = txtChassisNo.Text.Trim();
                _etiqacarmoredetail.HasHirePurchase = rdoYesHirePurchase.Checked;
                if (rdoYesHirePurchase.Checked == true)
                {
                    _etiqacarmoredetail.HPCompanyName = ddlHirePurchaseCompany.Text;
                }
                else
                {
                    _etiqacarmoredetail.HPCompanyName = "";
                }
                _etiqacarmoredetail.HasPreInsurer = true;
                if (ddlExistingInsurerName.Text != "177")
                {
                    _etiqacarmoredetail.PreInsurerName = ddlExistingInsurerName.Text;
                    _etiqacarmoredetail.PreInsPolicyNo = txtInsPolicyNo.Text.Trim();
                    _etiqacarmoredetail.PreInsExpiryDate = ddlDOCancellation.GetDate();
                }
                else
                {
                    _etiqacarmoredetail.PreInsurerName = ddlExistingInsurerName.Text;
                    _etiqacarmoredetail.PreInsPolicyNo = "";
                    _etiqacarmoredetail.PreInsExpiryDate = Convert.ToDateTime("1900-01-01 00:00:00.000");
                }
                _etiqacarmoredetail.HasDemeritPoints = rdoYesDermeritPoints.Checked;

                _etiqacarmoredetail.HasInsuranceTerminated = rdoYesInsuranceterminated.Checked;
                if (rdoYesInsuranceterminated.Checked == true)
                {
                    _etiqacarmoredetail.InsuranceTerminatedReason = txtITReason.Text.Trim();
                }
                else
                {
                    _etiqacarmoredetail.InsuranceTerminatedReason = "";
                }
                _etiqacarmoredetail.HasPhysicalImpairment = rdoYesPhysicalimpairment.Checked;
                if (rdoYesPhysicalimpairment.Checked == true)
                {
                    _etiqacarmoredetail.PhysicalImpairmentReason = txtPIReason.Text.Trim();
                }
                else
                {
                    _etiqacarmoredetail.PhysicalImpairmentReason = "";
                }

                string _totalPaymentAmount = "";
                string _paymentOrderNo = "";
                string val = GetOrderNumber();
                string[] _orderno = val.Split(',');
                _etiqacarmoredetail.OrderNo = _orderno[0].ToString();
                _paymentOrderNo = _orderno[0].ToString();
                _etiqacarmoredetail.OrderSerialNo = Convert.ToInt64(_orderno[1].ToString());

                //_etiqacarmoredetail.PaymentStatus = false;
                _etiqacarmoredetail.QuoteRefNo = lblQRefNo.Text.Trim();

                _etiqacarmoredetail.RefCEUserId = _UserId;
                _etiqacarmoredetail.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _etiqacarmoredetail.Status = true;
                _etiqacarmoredetail.CarResultId = _CXCTypeId;
                if (rdoNo.Checked == false && rdoYes.Checked == false)
                {
                    _etiqacarmoredetail.Info1 = "0";
                    _totalPaymentAmount = lblPremiumBeforeNCDProNoFormat.Text;
                }
                else if (rdoNo.Checked == true && rdoYes.Checked == false)
                {
                    _etiqacarmoredetail.Info1 = "0";
                    _totalPaymentAmount = lblPremiumBeforeNCDProNoFormat.Text;
                }
                if (rdoNo.Checked == false && rdoYes.Checked == true)
                {
                    _etiqacarmoredetail.Info1 = "1";
                    _totalPaymentAmount = lblPremiumAfterNCDProNoFormat.Text;
                }


                _etiqacarmoredetailCheck = _etiqacarmoredetaildb.GetCarMoreDetail(_CarId, _UserId);

                if (_etiqacarmoredetailCheck != null) //existing
                {
                    _etiqacarmoredetail.CECarMoreDetailId = _etiqacarmoredetailCheck.CECarMoreDetailId;
                }
                else
                {
                    _etiqacarmoredetail.CECarMoreDetailId = _CarMoreId;
                }

                _carmoreresult = _etiqacarmoredetaildb.Insert(_etiqacarmoredetail);

                if (_carmoreresult > 0)
                {
                    lblMessageSave.Text = "Proposal Details Saved (except payment details).";
                }
                else
                {
                    lblMessageSave.Text = "Proposal Details can't be save.";
                }

            }
        }
    }

    protected void LoadSavedDetails()
    {
        EtiqaCarMoreDetail _etiqacarmoredetailCheck = new EtiqaCarMoreDetail();
        EtiqaCarMoreDetailDB _etiqacarmoredetaildb = new EtiqaCarMoreDetailDB();

        _etiqacarmoredetailCheck = _etiqacarmoredetaildb.GetCarMoreDetail(_CarId, _UserId);

        if (_etiqacarmoredetailCheck != null)
        {
            txtName.Text = _etiqacarmoredetailCheck.Name;
            txtPostCode.Text = _etiqacarmoredetailCheck.PostalCode;
            txtUnit1.Text = _etiqacarmoredetailCheck.UnitNo;
            txtUnit2.Text = _etiqacarmoredetailCheck.HomeNo;
            txtAddress.Text = _etiqacarmoredetailCheck.Address;
            txtContactNo.PhoneNo = _etiqacarmoredetailCheck.ContactNo;

            ddlIdNumber.Prefix = _etiqacarmoredetailCheck.NRICNo.Substring(0,1);
            ddlIdNumber.Postfix = _etiqacarmoredetailCheck.NRICNo.Substring(8, 1);
            ddlIdNumber.IDNumber = _etiqacarmoredetailCheck.NRICNo.Substring(1, 7);

            ddlNationality.Nationality = _etiqacarmoredetailCheck.Nationality;
            txtVehicleNo.Text = _etiqacarmoredetailCheck.VechicleNo;
            txtEngineNo.Text = _etiqacarmoredetailCheck.EngineNo;
            txtChassisNo.Text = _etiqacarmoredetailCheck.ChassisNo;

            if (_etiqacarmoredetailCheck.HasHirePurchase)
            {
                rdoYesHirePurchase.Checked = true;
                ddlHirePurchaseCompany.Text = _etiqacarmoredetailCheck.HPCompanyName;
            }
            else
            {
                rdoYesHirePurchase.Checked = false;
                ddlHirePurchaseCompany.Text = "";
            }

            ddlExistingInsurerName.Text = _etiqacarmoredetailCheck.PreInsurerName;

            if (_etiqacarmoredetailCheck.PreInsurerName != "177")
            {
                
                txtInsPolicyNo.Text = _etiqacarmoredetailCheck.PreInsPolicyNo;
                ddlDOCancellation.Day = _etiqacarmoredetailCheck.PreInsExpiryDate.Day;
                ddlDOCancellation.Month = _etiqacarmoredetailCheck.PreInsExpiryDate.Month;
                ddlDOCancellation.Year = _etiqacarmoredetailCheck.PreInsExpiryDate.Year;
            }

            if (_etiqacarmoredetailCheck.HasDemeritPoints)
            {
                rdoYesDermeritPoints.Checked = true;
                txtITReason.Text = _etiqacarmoredetailCheck.InsuranceTerminatedReason;
            }
            else
            {
                rdoYesDermeritPoints.Checked = false;
                txtITReason.Text = "";
            }

            if (_etiqacarmoredetailCheck.HasPhysicalImpairment)
            {
                rdoYesPhysicalimpairment.Checked = true;
                txtPIReason.Text = _etiqacarmoredetailCheck.PhysicalImpairmentReason;
            }
            else
            {
                rdoYesPhysicalimpairment.Checked = false;
                txtPIReason.Text = "";
            }


            if (_etiqacarmoredetailCheck.Info1 == "1")
            {
                rdoNo.Checked = false;
                rdoYes.Checked = true;
            }


        }
    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        //Response.Redirect("~/car-insurance/results.aspx?sortby=0");
        Response.Redirect("~/car-insurance/your-request.aspx");
    }

    protected void imgbtnBackTop_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["FromSummary"] != null)
        {
            if (Session["FromSummary"].ToString().Trim() == "1")
            {
                Response.Redirect("~/car-insurance/results-new.aspx");
            }
            else
            {
                Response.Redirect("~/car-insurance/results-details.aspx");
            }
        }
        else
        {
            Response.Redirect("~/car-insurance/results-new.aspx");
        }
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void btnPostCode_Click(object sender, EventArgs e)
    {
        //txtAddress.Text = "";
        ////ChangeValidationEffectServerSide("maincardholder");
        //PostCode _postcode = new PostCode();
        //_postcode = GetPostCode(txtPostCode.Text);
        //if (_postcode != null)
        //{
        //    if (_postcode.BuildingName.Trim() != string.Empty)
        //    {
        //        txtAddress.Text += _postcode.BuildingName + ", ";
        //    }

        //    if (_postcode.StreetName.Trim() != string.Empty)
        //    {
        //        txtAddress.Text += _postcode.StreetName;
        //    }
        //}
        //else
        //{
        //    txtAddress.Text = "No Address Found.";
        //}
        //_postcode = null;
        txtPostCode_TextChanged(null, null);
    }

    public void LoadCarPolicyDetails()
    {
        if (Session[General.CarId] != null && Session[General.UserId] != null
            && Session[General.CarResultId] != null && Session[General.ProviderCompanyId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
            _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
        }
        else if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty
            && lblCarResultId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
        {
            _CarId = Convert.ToInt64(lblCarId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
            _CXCTypeId = Convert.ToInt64(lblCarResultId.Text);
            _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
        }

        //DataTable _dtProvider = new DataTable();
        DataSet _dtProvider = new DataSet();
        EtiqaCarMoreDetail _etiqacarmoredetail = new EtiqaCarMoreDetail();
        EtiqaCarMoreDetailDB _etiqacarmoredetaildb = new EtiqaCarMoreDetailDB();
        _dtProvider = _etiqacarmoredetaildb.GetCarPolicyDetails(_CarId, _UserId, _CXCTypeId, _ProviderId);
        if (_dtProvider != null)
        {
            if (_dtProvider.Tables[0].Rows.Count > 0 && _dtProvider.Tables[1].Rows.Count > 0 && _dtProvider.Tables[2].Rows.Count > 0)
            {
                //lblProvider.Text = _dtProvider.Rows[0]["CompanyName"].ToString();
                //lblPremium.Text = "$ " + _dtProvider.Rows[0]["AnnualPremium"].ToString();
                //lblPackage.Text = _dtProvider.Rows[0]["PlanName"].ToString();
                //lblPackageHead.Visible = true;
                //lblPremiumHead.Visible = true;
                lblYrofManufacture.Text = _dtProvider.Tables[0].Rows[0]["ManufactYear"].ToString();
                lblYrofRegister.Text = _dtProvider.Tables[0].Rows[0]["RegYear"].ToString();
                lblCarMakemodel.Text = _dtProvider.Tables[0].Rows[0]["MakeModelDesc"].ToString();
                lblOffpeakvehile.Text = _dtProvider.Tables[0].Rows[0]["Offbeak"].ToString();
                if (_dtProvider.Tables[0].Rows[0]["NCDPercent"].ToString() == "-1")
                {
                    lblNCDvalue.Text = "No NCD (First Policy)";
                }
                else
                {
                    lblNCDvalue.Text = _dtProvider.Tables[0].Rows[0]["NCDPercent"].ToString() + "%";
                }

                inputCurrentNCD.Value = _dtProvider.Tables[0].Rows[0]["NCDPercent"].ToString();
                inputNCD.Value = _dtProvider.Tables[0].Rows[0]["AppNCD"].ToString(); //ncd protect now based on 50% renewal ncd

                lblNCDRenewal.Text = _dtProvider.Tables[0].Rows[0]["AppNCD"].ToString() + "%";

                lblAnyclaim.Text = _dtProvider.Tables[0].Rows[0]["Claim"].ToString();
                inputClaim.Value = _dtProvider.Tables[0].Rows[0]["Claim"].ToString();
                lblOffenceDriving.Text = _dtProvider.Tables[0].Rows[0]["OffDriveCom"].ToString();
                if (_dtProvider.Tables[0].Rows[0]["AddDriver"].ToString() == "Yes")
                {
                    lblAddDriver.Text = _dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString();
                    txtDriverCount.Text = _dtProvider.Tables[0].Rows[0]["NoOfDriver"].ToString();
                }
                else
                {
                    lblAddDriver.Text = _dtProvider.Tables[0].Rows[0]["AddDriver"].ToString();
                    txtDriverCount.Text = "0";
                }
                EnableDriverPanels();
                lblCommencementdate.Text = _dtProvider.Tables[0].Rows[0]["CommenceDate"].ToString();

                DateTime dtCommencement = Convert.ToDateTime(lblCommencementdate.Text);
                ddlDOCancellation.Month = dtCommencement.Month;
                ddlDOCancellation.Day = dtCommencement.Day;
                ddlDOCancellation.Year = dtCommencement.Year;


                //Sakthi on 30 Nov 2011 -- Start
                Int32 _PromoValue = Convert.ToInt32(_dtProvider.Tables[1].Rows[0]["PetrolVoucher"].ToString());
                if (_PromoValue == 100)
                {
                    divPromoVoucher.Visible = true;
                    imgPromoAdd1.Visible = true;
                    imgPromoAdd2.Visible = false;
                }
                else if (_PromoValue == 50)
                {
                    divPromoVoucher.Visible = true;
                    imgPromoAdd1.Visible = false;
                    imgPromoAdd2.Visible = true;
                }
                else
                {
                    divPromoVoucher.Visible = false;
                    imgPromoAdd1.Visible = false;
                    imgPromoAdd2.Visible = false;
                }
                //Sakthi on 30 Nov 2011 -- Else

                lblSelectInsurer.Text = _dtProvider.Tables[1].Rows[0]["CompanyName"].ToString();
                lblPremiums.Text = "$" + _dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString();
                lblPremiumBeforeNCDProNoFormat.Text = _dtProvider.Tables[1].Rows[0]["AnnualPremium"].ToString();
                lblWorkshopPlan.Text = _dtProvider.Tables[1].Rows[0]["PlanName"].ToString();
                string convertno = General.GetRefNumber(_CarId);
                if (_ProviderId == 23)
                {
                    lblQRefNo.Text = "H" + convertno.ToString();
                }
                else if (_ProviderId == 29)
                {
                    lblQRefNo.Text = "L" + convertno.ToString();
                }
                else if (_ProviderId == 30)
                {
                    lblQRefNo.Text = "E" + convertno.ToString();
                }
            }
            else
            {
                //Response.Redirect("~/user/usermessage.aspx?errorcode=CI502");
                Response.Redirect("~/user/usermessage.aspx?mt=CI&ec=502");
            }
        }
        else
        {
            //Response.Redirect("~/user/usermessage.aspx?errorcode=CI502");
            Response.Redirect("~/user/usermessage.aspx?mt=CI&ec=502");
        }
        //else
        //{
        //    lblProvider.Text = "";
        //    lblPremium.Text = "";
        //    lblPackage.Text = "";
        //    lblPackageHead.Visible = false;
        //    lblPremiumHead.Visible = false;
        //}
        ddlExistingInsurerName.Text = _dtProvider.Tables[0].Rows[0]["Info1"].ToString();
        LoadCarDrivers();
    }

    private void LoadCarDrivers()
    {
        CarDriverDB _cardriverdb = new CarDriverDB();
        if (Session[General.CarId] != null && Session[General.UserId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
            _UserId = Convert.ToInt64(Session[General.UserId].ToString());
        }
        else if (lblCarId.Text != string.Empty && lblCustomerId.Text != null)
        {
            _CarId = Convert.ToInt64(lblCarId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
        }

        DataTable _driverList = _cardriverdb.GetDriverList(_CarId, _UserId);
        if (_driverList.Rows.Count > 0)
        {
            lblDriverId1.Text = _driverList.Rows[0]["CarDriverId"].ToString();

            DateTime _dtDOB1 = Convert.ToDateTime(_driverList.Rows[0]["DOB"].ToString());
            lblDriverDOB1.Text = _dtDOB1.Day.ToString("00") + "/" + _dtDOB1.Month.ToString("00") + "/" + _dtDOB1.Year.ToString("0000");
            ddlDriverGender1.Gender = _driverList.Rows[0]["Gender"].ToString();
            if (_driverList.Rows[0]["Gender"].ToString() == "M")
            {
                lblDriverGender1.Text = "Male";
            }
            else if (_driverList.Rows[0]["Gender"].ToString() == "F")
            {
                lblDriverGender1.Text = "Female";
            }
            if (_driverList.Rows[0]["Salutation"].ToString() != null && _driverList.Rows[0]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation1.Saluation = _driverList.Rows[0]["Salutation"].ToString();
            }
            if (_driverList.Rows[0]["Surname"].ToString() != null && _driverList.Rows[0]["Surname"].ToString() != "")
            {
                txtDriverSurName1.Text = _driverList.Rows[0]["Surname"].ToString();
            }
            if (_driverList.Rows[0]["GivenName"].ToString() != null && _driverList.Rows[0]["GivenName"].ToString() != "")
            {
                txtDriverGivenName1.Text = _driverList.Rows[0]["GivenName"].ToString();
            }
            if (_driverList.Rows[0]["IDType"].ToString() != null && _driverList.Rows[0]["IDType"].ToString() != "")
            {
                ddlDriverIdType1.IdType = _driverList.Rows[0]["IDType"].ToString();
            }
            if (_driverList.Rows[0]["IDNo"].ToString() != null && _driverList.Rows[0]["IDNo"].ToString() != "")
            {
                ddlDriverIdNumber1.Prefix = _driverList.Rows[0]["IDNo"].ToString().Substring(0, 1);
                ddlDriverIdNumber1.Postfix = _driverList.Rows[0]["IDNo"].ToString().Substring(8, 1);
                ddlDriverIdNumber1.IDNumber = _driverList.Rows[0]["IDNo"].ToString().Substring(1, 7);
            }
        }
        if (_driverList.Rows.Count > 1)
        {
            lblDriverId2.Text = _driverList.Rows[1]["CarDriverId"].ToString();

            DateTime _dtDOB2 = Convert.ToDateTime(_driverList.Rows[1]["DOB"].ToString());
            lblDriverDOB2.Text = _dtDOB2.Day.ToString("00") + "/" + _dtDOB2.Month.ToString("00") + "/" + _dtDOB2.Year.ToString("0000");
            ddlDriverGender2.Gender = _driverList.Rows[1]["Gender"].ToString();
            if (_driverList.Rows[1]["Gender"].ToString() == "M")
            {
                lblDriverGender2.Text = "Male";
            }
            else if (_driverList.Rows[1]["Gender"].ToString() == "F")
            {
                lblDriverGender2.Text = "Female";
            }
            if (_driverList.Rows[1]["Salutation"].ToString() != null && _driverList.Rows[1]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation2.Saluation = _driverList.Rows[1]["Salutation"].ToString();
            }
            if (_driverList.Rows[1]["Surname"].ToString() != null && _driverList.Rows[1]["Surname"].ToString() != "")
            {
                txtDriverSurName2.Text = _driverList.Rows[1]["Surname"].ToString();
            }
            if (_driverList.Rows[1]["GivenName"].ToString() != null && _driverList.Rows[1]["GivenName"].ToString() != "")
            {
                txtDriverGivenName2.Text = _driverList.Rows[1]["GivenName"].ToString();
            }
            if (_driverList.Rows[1]["IDType"].ToString() != null && _driverList.Rows[1]["IDType"].ToString() != "")
            {
                ddlDriverIdType2.IdType = _driverList.Rows[1]["IDType"].ToString();
            }
            if (_driverList.Rows[1]["IDNo"].ToString() != null && _driverList.Rows[1]["IDNo"].ToString() != "")
            {
                ddlDriverIdNumber2.Prefix = _driverList.Rows[1]["IDNo"].ToString().Substring(0, 1);
                ddlDriverIdNumber2.Postfix = _driverList.Rows[1]["IDNo"].ToString().Substring(8, 1);
                ddlDriverIdNumber2.IDNumber = _driverList.Rows[1]["IDNo"].ToString().Substring(1, 7);
            }
        }
        if (_driverList.Rows.Count > 2)
        {
            lblDriverId3.Text = _driverList.Rows[2]["CarDriverId"].ToString();

            DateTime _dtDOB3 = Convert.ToDateTime(_driverList.Rows[2]["DOB"].ToString());
            lblDriverDOB3.Text = _dtDOB3.Day.ToString("00") + "/" + _dtDOB3.Month.ToString("00") + "/" + _dtDOB3.Year.ToString("0000");
            ddlDriverGender3.Gender = _driverList.Rows[2]["Gender"].ToString();
            if (_driverList.Rows[2]["Gender"].ToString() == "M")
            {
                lblDriverGender3.Text = "Male";
            }
            else if (_driverList.Rows[2]["Gender"].ToString() == "F")
            {
                lblDriverGender3.Text = "Female";
            }
            if (_driverList.Rows[2]["Salutation"].ToString() != null && _driverList.Rows[2]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation3.Saluation = _driverList.Rows[0]["Salutation"].ToString();
            }
            if (_driverList.Rows[2]["Salutation"].ToString() != null && _driverList.Rows[2]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation3.Saluation = _driverList.Rows[2]["Salutation"].ToString();
            }
            if (_driverList.Rows[2]["Surname"].ToString() != null && _driverList.Rows[2]["Surname"].ToString() != "")
            {
                txtDriverSurName3.Text = _driverList.Rows[2]["Surname"].ToString();
            }
            if (_driverList.Rows[2]["GivenName"].ToString() != null && _driverList.Rows[2]["GivenName"].ToString() != "")
            {
                txtDriverGivenName3.Text = _driverList.Rows[2]["GivenName"].ToString();
            }
            if (_driverList.Rows[2]["IDType"].ToString() != null && _driverList.Rows[2]["IDType"].ToString() != "")
            {
                ddlDriverIdType3.IdType = _driverList.Rows[2]["IDType"].ToString();
            }
            if (_driverList.Rows[2]["IDNo"].ToString() != null && _driverList.Rows[2]["IDNo"].ToString() != "")
            {
                ddlDriverIdNumber3.Prefix = _driverList.Rows[2]["IDNo"].ToString().Substring(0, 1);
                ddlDriverIdNumber3.Postfix = _driverList.Rows[2]["IDNo"].ToString().Substring(8, 1);
                ddlDriverIdNumber3.IDNumber = _driverList.Rows[2]["IDNo"].ToString().Substring(1, 7);
            }
        }
        if (_driverList.Rows.Count > 3)
        {
            lblDriverId4.Text = _driverList.Rows[3]["CarDriverId"].ToString();

            DateTime _dtDOB4 = Convert.ToDateTime(_driverList.Rows[3]["DOB"].ToString());
            lblDriverDOB4.Text = _dtDOB4.Day.ToString("00") + "/" + _dtDOB4.Month.ToString("00") + "/" + _dtDOB4.Year.ToString("0000");
            ddlDriverGender4.Gender = _driverList.Rows[3]["Gender"].ToString();
            if (_driverList.Rows[3]["Gender"].ToString() == "M")
            {
                lblDriverGender4.Text = "Male";
            }
            else if (_driverList.Rows[3]["Gender"].ToString() == "F")
            {
                lblDriverGender4.Text = "Female";
            }
            if (_driverList.Rows[3]["Salutation"].ToString() != null && _driverList.Rows[3]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation4.Saluation = _driverList.Rows[3]["Salutation"].ToString();
            }
            if (_driverList.Rows[3]["Surname"].ToString() != null && _driverList.Rows[3]["Surname"].ToString() != "")
            {
                txtDriverSurName4.Text = _driverList.Rows[3]["Surname"].ToString();
            }
            if (_driverList.Rows[3]["GivenName"].ToString() != null && _driverList.Rows[3]["GivenName"].ToString() != "")
            {
                txtDriverGivenName4.Text = _driverList.Rows[3]["GivenName"].ToString();
            }
            if (_driverList.Rows[3]["IDType"].ToString() != null && _driverList.Rows[3]["IDType"].ToString() != "")
            {
                ddlDriverIdType4.IdType = _driverList.Rows[3]["IDType"].ToString();
            }
            if (_driverList.Rows[3]["IDNo"].ToString() != null && _driverList.Rows[3]["IDNo"].ToString() != "")
            {
                ddlDriverIdNumber4.Prefix = _driverList.Rows[3]["IDNo"].ToString().Substring(0, 1);
                ddlDriverIdNumber4.Postfix = _driverList.Rows[3]["IDNo"].ToString().Substring(8, 1);
                ddlDriverIdNumber4.IDNumber = _driverList.Rows[3]["IDNo"].ToString().Substring(1, 7);
            }
        }
        if (_driverList.Rows.Count > 4)
        {
            lblDriverId5.Text = _driverList.Rows[4]["CarDriverId"].ToString();

            DateTime _dtDOB5 = Convert.ToDateTime(_driverList.Rows[4]["DOB"].ToString());
            lblDriverDOB5.Text = _dtDOB5.Day.ToString("00") + "/" + _dtDOB5.Month.ToString("00") + "/" + _dtDOB5.Year.ToString("0000");
            ddlDriverGender5.Gender = _driverList.Rows[4]["Gender"].ToString();
            if (_driverList.Rows[4]["Gender"].ToString() == "M")
            {
                lblDriverGender5.Text = "Male";
            }
            else if (_driverList.Rows[4]["Gender"].ToString() == "F")
            {
                lblDriverGender5.Text = "Female";
            }
            if (_driverList.Rows[4]["Salutation"].ToString() != null && _driverList.Rows[4]["Salutation"].ToString() != "")
            {
                ddlDriverSalutation5.Saluation = _driverList.Rows[4]["Salutation"].ToString();
            }
            if (_driverList.Rows[4]["Surname"].ToString() != null && _driverList.Rows[4]["Surname"].ToString() != "")
            {
                txtDriverSurName5.Text = _driverList.Rows[4]["Surname"].ToString();
            }
            if (_driverList.Rows[4]["GivenName"].ToString() != null && _driverList.Rows[4]["GivenName"].ToString() != "")
            {
                txtDriverGivenName5.Text = _driverList.Rows[4]["GivenName"].ToString();
            }
            if (_driverList.Rows[4]["IDType"].ToString() != null && _driverList.Rows[4]["IDType"].ToString() != "")
            {
                ddlDriverIdType5.IdType = _driverList.Rows[4]["IDType"].ToString();
            }
            if (_driverList.Rows[4]["IDNo"].ToString() != null && _driverList.Rows[4]["IDNo"].ToString() != "")
            {
                ddlDriverIdNumber5.Prefix = _driverList.Rows[4]["IDNo"].ToString().Substring(0, 1);
                ddlDriverIdNumber5.Postfix = _driverList.Rows[4]["IDNo"].ToString().Substring(8, 1);
                ddlDriverIdNumber5.IDNumber = _driverList.Rows[4]["IDNo"].ToString().Substring(1, 7);
            }
        }
    }

    private void CheckValidation()
    {
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);
        txtVehicleNo.Text = General.ClearScriptTag(txtVehicleNo.Text);
        txtEngineNo.Text = General.ClearScriptTag(txtEngineNo.Text);
        txtChassisNo.Text = General.ClearScriptTag(txtChassisNo.Text);
        txtInsPolicyNo.Text = General.ClearScriptTag(txtInsPolicyNo.Text);
        txtPIReason.Text = General.ClearScriptTag(txtPIReason.Text);
        txtITReason.Text = General.ClearScriptTag(txtITReason.Text);

        #region Hire Purchase
        if (rdoYesHirePurchase.Checked)
        {
            rfvHirePurchaseCompany.Enabled = true;
            //rfvHirePurchase.Enabled = false;
        }
        else
        {
            rfvHirePurchaseCompany.Enabled = false;
            //rfvHirePurchase.Enabled = false;
        }
        #endregion

        #region Pre Insurance
        //if (rdoYesExistingInsurer.Checked)
        if (ddlExistingInsurerName.Text != "177")
        {
            rfvExistingInsurerName.Enabled = true;
            rfvInsPolicyNo.Enabled = true;
            ddlDOCancellation.IsEnableValidation(true);
        }
        else
        {
            rfvExistingInsurerName.Enabled = true;
            rfvInsPolicyNo.Enabled = false;
            ddlDOCancellation.IsEnableValidation(false);
        }
        #endregion

        #region Demerit Points
        if (rdoYesDermeritPoints.Checked)
        {
            rfvDrivername1.Enabled = true;
            rfvTotalpoints1.Enabled = true;
            //rfvDermeritPoints.Enabled = false;
        }
        else
        {
            rfvDrivername1.Enabled = false;
            rfvTotalpoints1.Enabled = false;
            //rfvDermeritPoints.Enabled = false;
        }
        #endregion

        #region Physical Impairment
        if (rdoYesPhysicalimpairment.Checked)
        {
            rfvPIReason.Enabled = true;
            //rfvPhysicalimpairment.Enabled = false;
        }
        else
        {
            rfvPIReason.Enabled = false;
            //rfvPhysicalimpairment.Enabled = false;
        }
        #endregion

        #region Insurance Terminated
        if (rdoYesInsuranceterminated.Checked)
        {
            rfvITReason.Enabled = true;
            //rfvInsuranceterminated.Enabled = false;
        }
        else
        {
            rfvITReason.Enabled = false;
            //rfvInsuranceterminated.Enabled = false;
        }
        #endregion

    }

    private void CheckValidationSave()
    {
        txtName.Text = General.ClearScriptTag(txtName.Text);
        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);
        txtVehicleNo.Text = General.ClearScriptTag(txtVehicleNo.Text);
        txtEngineNo.Text = General.ClearScriptTag(txtEngineNo.Text);
        txtChassisNo.Text = General.ClearScriptTag(txtChassisNo.Text);
        txtInsPolicyNo.Text = General.ClearScriptTag(txtInsPolicyNo.Text);
        txtPIReason.Text = General.ClearScriptTag(txtPIReason.Text);
        txtITReason.Text = General.ClearScriptTag(txtITReason.Text);


        #region Hire Purchase
        if (rdoYesHirePurchase.Checked)
        {
            rfvHirePurchaseCompanySave.Enabled = true;
            //rfvHirePurchase.Enabled = false;
        }
        else
        {
            rfvHirePurchaseCompanySave.Enabled = false;
            //rfvHirePurchase.Enabled = false;
        }
        #endregion

        #region Pre Insurance
        //if (rdoYesExistingInsurer.Checked)
        if (ddlExistingInsurerName.Text != "177")
        {
            rfvExistingInsurerNameSave.Enabled = true;
            rfvInsPolicyNoSave.Enabled = true;
            ddlDOCancellation.IsEnableValidation(true);
        }
        else
        {
            rfvExistingInsurerNameSave.Enabled = true;
            rfvInsPolicyNoSave.Enabled = false;
            ddlDOCancellation.IsEnableValidation(false);
        }
        #endregion

        #region Demerit Points
        if (rdoYesDermeritPoints.Checked)
        {
            rfvDrivername1Save.Enabled = true;
            rfvTotalpoints1Save.Enabled = true;
            //rfvDermeritPoints.Enabled = false;
        }
        else
        {
            rfvDrivername1Save.Enabled = false;
            rfvTotalpoints1Save.Enabled = false;
            //rfvDermeritPoints.Enabled = false;
        }
        #endregion

        #region Physical Impairment
        if (rdoYesPhysicalimpairment.Checked)
        {
            rfvPIReasonSave.Enabled = true;
            //rfvPhysicalimpairment.Enabled = false;
        }
        else
        {
            rfvPIReasonSave.Enabled = false;
            //rfvPhysicalimpairment.Enabled = false;
        }
        #endregion

        #region Insurance Terminated
        if (rdoYesInsuranceterminated.Checked)
        {
            rfvITReasonSave.Enabled = true;
            //rfvInsuranceterminated.Enabled = false;
        }
        else
        {
            rfvITReasonSave.Enabled = false;
            //rfvInsuranceterminated.Enabled = false;
        }
        #endregion

    }

    private bool SaveDemeritPoints()
    {
        //bool _result = false;
        Int64 _demeritresult = 0;
        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.CarId] != null
            && Session[CE.Global.General.ProviderCompanyId] != null && Session[CE.Global.General.CarMoreDetailId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            _CarId = Convert.ToInt64(Session[CE.Global.General.CarId].ToString());
            _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
            _CarMoreId = Convert.ToInt64(Session[CE.Global.General.CarMoreDetailId].ToString());
        }
        else if (lblCustomerId.Text != string.Empty && lblCarId.Text != string.Empty
            && lblProviderCompanyId.Text != string.Empty && lblCarMoreDetailId.Text != string.Empty)
        {
            _UserId = Convert.ToInt64(lblCustomerId.Text);
            _CarId = Convert.ToInt64(lblCarId.Text);
            _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
            _CarMoreId = Convert.ToInt64(lblCarMoreDetailId.Text);
        }

        if (txtDrivername1.Text != string.Empty && txtTotalpoints1.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername1.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints1.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        if (txtDrivername2.Text != string.Empty && txtTotalpoints2.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername2.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints2.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        if (txtDrivername3.Text != string.Empty && txtTotalpoints3.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername3.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints3.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        if (txtDrivername4.Text != string.Empty && txtTotalpoints4.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername4.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints4.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        if (txtDrivername5.Text != string.Empty && txtTotalpoints5.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername5.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints5.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        if (txtDrivername6.Text != string.Empty && txtTotalpoints6.Text != string.Empty)
        {
            CarDriverDemeritPoints _cardriverdemeritpoints = new CarDriverDemeritPoints();
            CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
            _cardriverdemeritpoints.CECarID = _CarId;
            _cardriverdemeritpoints.CECarMoreDetailId = _CarMoreId;
            _cardriverdemeritpoints.ProviderCompanyId = _ProviderId;
            _cardriverdemeritpoints.DriverName = txtDrivername6.Text.ToUpper();
            _cardriverdemeritpoints.TotalDemeritPoints = txtTotalpoints6.Text;
            _cardriverdemeritpoints.RefCEUserId = _UserId;
            _cardriverdemeritpoints.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _cardriverdemeritpoints.Status = true;
            _demeritresult += _cardriverdemeritpointsdb.InsertEtiqa(_cardriverdemeritpoints);
            _cardriverdemeritpoints = null;
            _cardriverdemeritpointsdb = null;
        }

        return _demeritresult > 0;
    }

    private bool UpdateDriverDetails()
    {
        bool _result = false;
        //Int64 _demeritresult = 0;
        CarDriver _cardriver = new CarDriver();
        CarDriverDB _cardriverdb = new CarDriverDB();

        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.CarId] != null)
        {
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            _CarId = Convert.ToInt64(Session[CE.Global.General.CarId].ToString());
        }
        else if (Request.Params["customerid"] != null && Request.Params["carid"] != null)
        {
            _UserId = Convert.ToInt64(lblCustomerId.Text);
            _CarId = Convert.ToInt64(lblCarId.Text);
        }

        if (txtDriverCount.Text.Trim() != "0")
        {
            int _drivercount = Convert.ToInt32(txtDriverCount.Text.Trim());
            int _insertcount = 0;

            for (int i = 1; i <= _drivercount; i++)
            {
                _cardriver.StepId = 2;
                _cardriver.RerCEUserId = _UserId;
                _cardriver.CECarId = _CarId;
                if (i == 1)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId1.Text.Trim());
                    _cardriver.Salutation = ddlDriverSalutation1.GetSalutation();
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName1.Text.ToUpper()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName1.Text.ToUpper()));
                    _cardriver.IDType = ddlDriverIdType1.GetIDType();
                    _cardriver.IDNo = ddlDriverIdNumber1.GetIdNumber();
                    _cardriver.DOB = CE.Global.General.GetUTCDateTime();
                    _cardriver.Status = "Active";
                }
                else if (i == 2)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId2.Text.Trim());
                    _cardriver.Salutation = ddlDriverSalutation2.GetSalutation();
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName2.Text.ToUpper()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName2.Text.ToUpper()));
                    _cardriver.IDType = ddlDriverIdType2.GetIDType();
                    _cardriver.IDNo = ddlDriverIdNumber2.GetIdNumber();
                    _cardriver.DOB = CE.Global.General.GetUTCDateTime();
                    _cardriver.Status = "Active";
                }
                else if (i == 3)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId3.Text.Trim());
                    _cardriver.Salutation = ddlDriverSalutation3.GetSalutation();
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName3.Text.ToUpper()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName3.Text.ToUpper()));
                    _cardriver.IDType = ddlDriverIdType3.GetIDType();
                    _cardriver.IDNo = ddlDriverIdNumber3.GetIdNumber();
                    _cardriver.DOB = CE.Global.General.GetUTCDateTime();
                    _cardriver.Status = "Active";
                }
                else if (i == 4)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId4.Text.Trim());
                    _cardriver.Salutation = ddlDriverSalutation4.GetSalutation();
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName4.Text.ToUpper()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName4.Text.ToUpper()));
                    _cardriver.IDType = ddlDriverIdType4.GetIDType();
                    _cardriver.IDNo = ddlDriverIdNumber4.GetIdNumber();
                    _cardriver.DOB = CE.Global.General.GetUTCDateTime();
                    _cardriver.Status = "Active";
                }
                else if (i == 5)
                {
                    _cardriver.CarDriverId = Convert.ToInt64(lblDriverId5.Text.Trim());
                    _cardriver.Salutation = ddlDriverSalutation5.GetSalutation();
                    _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriverSurName5.Text.ToUpper()));
                    _cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(txtDriverGivenName5.Text.ToUpper()));
                    _cardriver.IDType = ddlDriverIdType5.GetIDType();
                    _cardriver.IDNo = ddlDriverIdNumber5.GetIdNumber();
                    _cardriver.DOB = CE.Global.General.GetUTCDateTime();
                    _cardriver.Status = "Active";
                }
                _cardriver.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                if (_cardriverdb.Insert(_cardriver) > 0)
                {
                    _insertcount++;
                    _result = true;
                }
            }
            _cardriverdb = null;
            _cardriver = null;
        }
        return _result;
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";
        _InsuranceName = "Car Insurance";
        if (lblProviderCompanyId.Text != string.Empty && lblCarId.Text != string.Empty)
        {
            _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
            _CarId = Convert.ToInt64(lblCarId.Text);
        }
        else if (Session[General.ProviderCompanyId] != null && Session[General.CarId] != null)
        {
            _ProviderId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
        }

        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = " + _ProviderId.ToString();
        _dtProvider = _db.GetDataTable(_strSql);
        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
            //_providerEmail = _dtProvider.Rows[0]["Email1"].ToString();            
            _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaCI_TO");
            _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaCI_CC");
            _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaCI_BCC");
        }
        _strSql = "";
        _providerName += " Insurance";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblCarMoreDetail_Etiqa WHERE CECarId = " + _CarId.ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }
        //_RefNo = General.GetRefNumber("CI", _Date, Session[General.CarId].ToString());
        _RefNo = lblQRefNo.Text.Trim();
        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("CI", Request, "Car Insurance Etiqa proposal form.");
    }

    private PostCode GetPostCode(string strPostCode)
    {
        PostCode _postcode = new PostCode();
        PostCodeDB _postcodedb = new PostCodeDB();
        _postcode = _postcodedb.GetPostCode(strPostCode);
        _postcodedb = null;
        return _postcode;
    }

    private void ShowCarMoreDetail(Int64 CarId, Int64 CEId)
    {
        EtiqaCarMoreDetail _etiqacarmoredetail = new EtiqaCarMoreDetail();
        EtiqaCarMoreDetailDB _etiqacarmoredetaildb = new EtiqaCarMoreDetailDB();
        _etiqacarmoredetail = _etiqacarmoredetaildb.GetCarMoreDetail(CarId, CEId);
        if (_etiqacarmoredetail != null)
        {
            CarMoreDetailSetProperty(_etiqacarmoredetail);
        }
        _etiqacarmoredetail = null;
        _etiqacarmoredetaildb = null;
    }

    private void CarMoreDetailSetProperty(EtiqaCarMoreDetail _etiqacarmoredetail)
    {

        if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
        {
            lblCarMoreDetailId.Text = _etiqacarmoredetail.CECarMoreDetailId.ToString();
        }
        else
        {
            Session[General.CarMoreDetailId] = _etiqacarmoredetail.CECarMoreDetailId.ToString();
        }

        txtName.Text = _etiqacarmoredetail.Name.ToString();
        txtPostCode.Text = _etiqacarmoredetail.PostalCode.ToString();
        txtUnit1.Text = _etiqacarmoredetail.UnitNo.ToString();
        txtUnit2.Text = _etiqacarmoredetail.HomeNo.ToString();
        txtAddress.Text = _etiqacarmoredetail.Address.ToString();
        txtAddress.ReadOnly = true;
        txtContactNo.PhoneNo = _etiqacarmoredetail.ContactNo.ToString();

        if (_etiqacarmoredetail.NRICNo.Length == 9)
        {
            ddlIdNumber.Prefix = _etiqacarmoredetail.NRICNo[0].ToString();
            ddlIdNumber.Postfix = _etiqacarmoredetail.NRICNo[8].ToString();
            ddlIdNumber.IDNumber = _etiqacarmoredetail.NRICNo.Substring(1, 7);
        }
        ddlNationality.Nationality = _etiqacarmoredetail.Nationality;
        txtVehicleNo.Text = _etiqacarmoredetail.VechicleNo.ToString();
        txtEngineNo.Text = _etiqacarmoredetail.EngineNo.ToString();
        txtChassisNo.Text = _etiqacarmoredetail.ChassisNo.ToString();
        if (_etiqacarmoredetail.HasHirePurchase == true)
        {
            rdoYesHirePurchase.Checked = true;
            txtHirePurchase.Text = "1";

            ddlHirePurchaseCompany.Text = _etiqacarmoredetail.HPCompanyName.ToString();
        }
        else
        {
            rdoNoHirePurchase.Checked = true;
            txtHirePurchase.Text = "1";

            ddlHirePurchaseCompany.Text = "";
        }
        if (_etiqacarmoredetail.HasPreInsurer == true)
        {
            //rdoYesExistingInsurer.Checked = true;
            //txtExistingInsurer.Text = "1";

            ddlExistingInsurerName.Text = _etiqacarmoredetail.PreInsurerName.ToString();
            txtInsPolicyNo.Text = _etiqacarmoredetail.PreInsPolicyNo.ToString();
            ddlDOCancellation.Day = _etiqacarmoredetail.PreInsExpiryDate.Day;
            ddlDOCancellation.Month = _etiqacarmoredetail.PreInsExpiryDate.Month;
            ddlDOCancellation.Year = _etiqacarmoredetail.PreInsExpiryDate.Year;
        }
        else
        {
            //rdoNoExistingInsurer.Checked = true;
            //txtExistingInsurer.Text = "1";

            ddlExistingInsurerName.Text = _etiqacarmoredetail.PreInsurerName.ToString();
            txtInsPolicyNo.Text = "";
        }
        if (_etiqacarmoredetail.HasDemeritPoints == true)
        {
            rdoYesDermeritPoints.Checked = true;
            txtDermeritPoints.Text = "1";
            _CarMoreId = _etiqacarmoredetail.CECarMoreDetailId;//Convert.ToInt64(Session[General.CarMoreDetailId].ToString());
            ShowCarDriverDemeritPoints(_CarId, _CarMoreId, _UserId, _ProviderId);
        }
        else
        {
            rdoNoDermeritPoints.Checked = true;
            txtDermeritPoints.Text = "1";
        }
        if (_etiqacarmoredetail.HasPhysicalImpairment == true)
        {
            rdoYesPhysicalimpairment.Checked = true;
            txtPhysicalimpairment.Text = "1";

            txtPIReason.Text = _etiqacarmoredetail.PhysicalImpairmentReason.ToString();
        }
        else
        {
            rdoNoPhysicalimpairment.Checked = true;
            txtPhysicalimpairment.Text = "1";

            txtPIReason.Text = "";
        }
        if (_etiqacarmoredetail.HasInsuranceTerminated == true)
        {
            rdoYesInsuranceterminated.Checked = true;
            txtInsuranceterminated.Text = "1";

            txtITReason.Text = _etiqacarmoredetail.InsuranceTerminatedReason.ToString();
        }
        else
        {
            rdoNoInsuranceterminated.Checked = true;
            txtInsuranceterminated.Text = "1";

            txtITReason.Text = "";
        }
    }

    private void ShowCarDriverDemeritPoints(Int64 CarId, Int64 CarMoreId, Int64 CEId, Int64 ProiderId)
    {
        DataSet _dsdemeritpoints = new DataSet();
        CarDriverDemeritPointsDB _cardriverdemeritpointsdb = new CarDriverDemeritPointsDB();
        _dsdemeritpoints = _cardriverdemeritpointsdb.GetCarDriverDemeritPointsEtiqa(CarId, CarMoreId, CEId, ProiderId);
        if (_dsdemeritpoints.Tables[0].Rows.Count > 0)
        {
            txtDrivername1.Text = _dsdemeritpoints.Tables[0].Rows[0]["DriverName"].ToString();
            txtTotalpoints1.Text = _dsdemeritpoints.Tables[0].Rows[0]["TotalDemeritPoints"].ToString();
            if (_dsdemeritpoints.Tables[0].Rows.Count > 1)
            {
                txtDrivername2.Text = _dsdemeritpoints.Tables[0].Rows[1]["DriverName"].ToString();
                txtTotalpoints2.Text = _dsdemeritpoints.Tables[0].Rows[1]["TotalDemeritPoints"].ToString();
            }
            if (_dsdemeritpoints.Tables[0].Rows.Count > 2)
            {
                txtDrivername3.Text = _dsdemeritpoints.Tables[0].Rows[2]["DriverName"].ToString();
                txtTotalpoints3.Text = _dsdemeritpoints.Tables[0].Rows[2]["TotalDemeritPoints"].ToString();
            }
            if (_dsdemeritpoints.Tables[0].Rows.Count > 3)
            {
                txtDrivername4.Text = _dsdemeritpoints.Tables[0].Rows[3]["DriverName"].ToString();
                txtTotalpoints4.Text = _dsdemeritpoints.Tables[0].Rows[3]["TotalDemeritPoints"].ToString();
            }
            if (_dsdemeritpoints.Tables[0].Rows.Count > 4)
            {
                txtDrivername5.Text = _dsdemeritpoints.Tables[0].Rows[4]["DriverName"].ToString();
                txtTotalpoints5.Text = _dsdemeritpoints.Tables[0].Rows[4]["TotalDemeritPoints"].ToString();
            }
            if (_dsdemeritpoints.Tables[0].Rows.Count > 5)
            {
                txtDrivername6.Text = _dsdemeritpoints.Tables[0].Rows[5]["DriverName"].ToString();
                txtTotalpoints6.Text = _dsdemeritpoints.Tables[0].Rows[5]["TotalDemeritPoints"].ToString();
            }
        }
        _cardriverdemeritpointsdb = null;
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Proposal Details
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }
        //Postal Code
        if (rfvPostCode.Enabled && rfvPostCode.ValidationGroup == strValidationGroup)
        {
            rfvPostCode.Validate();
            if (rfvPostCode.IsValid == false)
            {
                txtPostCode.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPostCode.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        if (revPostCode.Enabled && revPostCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostCode.IsValid)
            {
                revPostCode.Validate();
                if (revPostCode.IsValid == false)
                {
                    txtPostCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtPostCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        //Unit No
        if (rfvUnit1.Enabled && rfvUnit1.ValidationGroup == strValidationGroup)
        {
            rfvUnit1.Validate();
            if (rfvUnit1.IsValid == false)
            {
                txtUnit1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit1.ControlStyle.CssClass = "";
        }

        //Home No
        if (rfvUnit2.Enabled && rfvUnit2.ValidationGroup == strValidationGroup)
        {
            rfvUnit2.Validate();
            if (rfvUnit2.IsValid == false)
            {
                txtUnit2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit2.ControlStyle.CssClass = "";
        }

        //Address
        if (rfvAddress.Enabled && rfvAddress.ValidationGroup == strValidationGroup)
        {
            rfvAddress.Validate();
            if (rfvAddress.IsValid == false)
            {
                txtAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtAddress.ControlStyle.CssClass = "";
        }

        //if (revAddress.Enabled && revAddress.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvAddress.IsValid)
        //    {
        //        revAddress.Validate();
        //        if (revAddress.IsValid == false)
        //        {
        //            txtAddress.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtAddress.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtAddress.ControlStyle.CssClass = "";
        //}

        //Applicant's Contact Number
        txtContactNo.ChangeValidationEffectServerSide(strValidationGroup);

        //Applicant's NRIC Number
        ddlIdNumber.ChangeValidationEffectServerSide(strValidationGroup);

        //Applicant's Nationality
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Purticulas of Vehicle

        //VehicleNo
        if (rfvVehicleNo.Enabled && rfvVehicleNo.ValidationGroup == strValidationGroup)
        {
            rfvVehicleNo.Validate();
            if (rfvVehicleNo.IsValid == false)
            {
                txtVehicleNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtVehicleNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtVehicleNo.ControlStyle.CssClass = "";
        }

        //EngineNo
        if (rfvEngineNo.Enabled && rfvEngineNo.ValidationGroup == strValidationGroup)
        {
            rfvEngineNo.Validate();
            if (rfvEngineNo.IsValid == false)
            {
                txtEngineNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtEngineNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtEngineNo.ControlStyle.CssClass = "";
        }
        //ChassisNo
        if (rfvChassisNo.Enabled && rfvChassisNo.ValidationGroup == strValidationGroup)
        {
            rfvChassisNo.Validate();
            if (rfvChassisNo.IsValid == false)
            {
                txtChassisNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChassisNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChassisNo.ControlStyle.CssClass = "";
        }

        //Hire Purchase
        if (rfvHirePurchase.Enabled && rfvHirePurchase.ValidationGroup == strValidationGroup)
        {
            rfvHirePurchase.Validate();
            if (rfvHirePurchase.IsValid == false)
            {
                lblYesHirePurchase.ControlStyle.CssClass = "validationError";
                lblNoHirePurchase.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesHirePurchase.ControlStyle.CssClass = "";
                lblNoHirePurchase.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesHirePurchase.ControlStyle.CssClass = "";
            lblNoHirePurchase.ControlStyle.CssClass = "";
        }
        //HirePurchaseCompany
        if (rfvHirePurchaseCompany.Enabled && rfvHirePurchaseCompany.ValidationGroup == strValidationGroup)
        {
            rfvHirePurchaseCompany.Validate();
            if (rfvHirePurchaseCompany.IsValid == false)
            {
                ddlHirePurchaseCompany.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlHirePurchaseCompany.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlHirePurchaseCompany.ControlStyle.CssClass = "";
        }

        //Existing Insurer
        //if (rfvExistingInsurer.Enabled && rfvExistingInsurer.ValidationGroup == strValidationGroup)
        //{
        //    rfvExistingInsurer.Validate();
        //    if (rfvExistingInsurer.IsValid == false)
        //    {
        //        lblYesExistingInsurer.ControlStyle.CssClass = "validationError";
        //        lblNoExistingInsurer.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        lblYesExistingInsurer.ControlStyle.CssClass = "";
        //        lblNoExistingInsurer.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    lblYesExistingInsurer.ControlStyle.CssClass = "";
        //    lblNoExistingInsurer.ControlStyle.CssClass = "";
        //}

        //Insurance Company
        if (rfvExistingInsurerName.Enabled && rfvExistingInsurerName.ValidationGroup == strValidationGroup)
        {
            rfvExistingInsurerName.Validate();
            if (rfvExistingInsurerName.IsValid == false)
            {
                ddlExistingInsurerName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlExistingInsurerName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlExistingInsurerName.ControlStyle.CssClass = "";
        }

        //Insurance Policy No
        if (rfvInsPolicyNo.Enabled && rfvInsPolicyNo.ValidationGroup == strValidationGroup)
        {
            rfvInsPolicyNo.Validate();
            if (rfvInsPolicyNo.IsValid == false)
            {
                txtInsPolicyNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsPolicyNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsPolicyNo.ControlStyle.CssClass = "";
        }
        //Insurance Date Of Cancellation
        ddlDOCancellation.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region General Question

        //DermeritPoints
        if (rfvDermeritPoints.Enabled && rfvDermeritPoints.ValidationGroup == strValidationGroup)
        {
            rfvDermeritPoints.Validate();
            if (rfvDermeritPoints.IsValid == false)
            {
                lblYesDermeritPoints.ControlStyle.CssClass = "validationError";
                lblNoDermeritPoints.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesDermeritPoints.ControlStyle.CssClass = "";
                lblNoDermeritPoints.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesDermeritPoints.ControlStyle.CssClass = "";
            lblNoDermeritPoints.ControlStyle.CssClass = "";
        }
        //Drivername
        if (rfvDrivername1.Enabled && rfvDrivername1.ValidationGroup == strValidationGroup)
        {
            rfvDrivername1.Validate();
            if (rfvDrivername1.IsValid == false)
            {
                txtDrivername1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDrivername1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDrivername1.ControlStyle.CssClass = "";
        }
        //Totalpoints
        if (rfvTotalpoints1.Enabled && rfvTotalpoints1.ValidationGroup == strValidationGroup)
        {
            rfvTotalpoints1.Validate();
            if (rfvTotalpoints1.IsValid == false)
            {
                txtTotalpoints1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtTotalpoints1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtTotalpoints1.ControlStyle.CssClass = "";
        }

        //Physicalimpairment
        if (rfvPhysicalimpairment.Enabled && rfvPhysicalimpairment.ValidationGroup == strValidationGroup)
        {
            rfvPhysicalimpairment.Validate();
            if (rfvPhysicalimpairment.IsValid == false)
            {
                lblYesPhysicalimpairment.ControlStyle.CssClass = "validationError";
                lblNoPhysicalimpairment.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesPhysicalimpairment.ControlStyle.CssClass = "";
                lblNoPhysicalimpairment.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesPhysicalimpairment.ControlStyle.CssClass = "";
            lblNoPhysicalimpairment.ControlStyle.CssClass = "";
        }
        //Physicalimpairment Reason
        if (rfvPIReason.Enabled && rfvPIReason.ValidationGroup == strValidationGroup)
        {
            rfvPIReason.Validate();
            if (rfvPIReason.IsValid == false)
            {
                txtPIReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPIReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPIReason.ControlStyle.CssClass = "";
        }

        //Insurance Terminated Reason
        if (rfvITReason.Enabled && rfvITReason.ValidationGroup == strValidationGroup)
        {
            rfvITReason.Validate();
            if (rfvITReason.IsValid == false)
            {
                txtITReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtITReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtITReason.ControlStyle.CssClass = "";
        }

        //Insurance Terminated
        if (rfvInsuranceterminated.Enabled && rfvInsuranceterminated.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceterminated.Validate();
            if (rfvInsuranceterminated.IsValid == false)
            {
                lblYesInsuranceterminated.ControlStyle.CssClass = "validationError";
                lblNoInsuranceterminated.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesInsuranceterminated.ControlStyle.CssClass = "";
                lblNoInsuranceterminated.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesInsuranceterminated.ControlStyle.CssClass = "";
            lblNoInsuranceterminated.ControlStyle.CssClass = "";
        }

        #endregion

        #region Drivers
        //Driver 1 **************************************************************
        //Salutation
        ddlDriverSalutation1.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvDriverSurName1.Enabled && rfvDriverSurName1.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName1.Validate();
            if (rfvDriverSurName1.IsValid == false)
            {
                txtDriverSurName1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName1.ControlStyle.CssClass = "";
        }

        //SalGender
        ddlDriverGender1.ChangeValidationEffectServerSide(strValidationGroup);
        if (csvDriverSalGender1.Enabled && csvDriverSalGender1.ValidationGroup == strValidationGroup)
        {
            if (ddlDriverSalutation1.IsValidRequirement() && ddlDriverGender1.IsValidRequirement())
            {
                csvDriverSalGender1.Validate();
                if (csvDriverSalGender1.IsValid == false)
                {
                    ddlDriverSalutation1.ChangeValidateEffect(true);
                }
                else
                {
                    ddlDriverSalutation1.ChangeValidateEffect(false);
                }
            }
        }
        else
        {
            ddlDriverSalutation1.ChangeValidateEffect(false);
        }

        //Type of Indentification
        ddlDriverIdType1.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlDriverIdNumber1.ChangeValidationEffectServerSide(strValidationGroup);

        //Driver 2 **************************************************************
        //Salutation
        ddlDriverSalutation2.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvDriverSurName2.Enabled && rfvDriverSurName2.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName2.Validate();
            if (rfvDriverSurName2.IsValid == false)
            {
                txtDriverSurName2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName2.ControlStyle.CssClass = "";
        }

        //SalGender
        ddlDriverGender2.ChangeValidationEffectServerSide(strValidationGroup);
        if (csvDriverSalGender2.Enabled && csvDriverSalGender2.ValidationGroup == strValidationGroup)
        {
            if (ddlDriverSalutation2.IsValidRequirement() && ddlDriverGender2.IsValidRequirement())
            {
                csvDriverSalGender1.Validate();
                if (csvDriverSalGender2.IsValid == false)
                {
                    ddlDriverSalutation2.ChangeValidateEffect(true);
                }
                else
                {
                    ddlDriverSalutation2.ChangeValidateEffect(false);
                }
            }
        }
        else
        {
            ddlDriverSalutation2.ChangeValidateEffect(false);
        }

        //Type of Indentification
        ddlDriverIdType2.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlDriverIdNumber2.ChangeValidationEffectServerSide(strValidationGroup);

        //Driver 3 **************************************************************
        //Salutation
        ddlDriverSalutation3.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvDriverSurName3.Enabled && rfvDriverSurName3.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName3.Validate();
            if (rfvDriverSurName3.IsValid == false)
            {
                txtDriverSurName3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName3.ControlStyle.CssClass = "";
        }

        //SalGender
        ddlDriverGender3.ChangeValidationEffectServerSide(strValidationGroup);
        if (csvDriverSalGender3.Enabled && csvDriverSalGender3.ValidationGroup == strValidationGroup)
        {
            if (ddlDriverSalutation3.IsValidRequirement() && ddlDriverGender3.IsValidRequirement())
            {
                csvDriverSalGender3.Validate();
                if (csvDriverSalGender3.IsValid == false)
                {
                    ddlDriverSalutation3.ChangeValidateEffect(true);
                }
                else
                {
                    ddlDriverSalutation3.ChangeValidateEffect(false);
                }
            }
        }
        else
        {
            ddlDriverSalutation3.ChangeValidateEffect(false);
        }

        //Type of Indentification
        ddlDriverIdType3.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlDriverIdNumber3.ChangeValidationEffectServerSide(strValidationGroup);
        //Driver 4 **************************************************************
        //Salutation
        ddlDriverSalutation4.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvDriverSurName4.Enabled && rfvDriverSurName4.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName4.Validate();
            if (rfvDriverSurName4.IsValid == false)
            {
                txtDriverSurName4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName4.ControlStyle.CssClass = "";
        }

        //SalGender
        ddlDriverGender4.ChangeValidationEffectServerSide(strValidationGroup);
        if (csvDriverSalGender4.Enabled && csvDriverSalGender4.ValidationGroup == strValidationGroup)
        {
            if (ddlDriverSalutation4.IsValidRequirement() && ddlDriverGender4.IsValidRequirement())
            {
                csvDriverSalGender4.Validate();
                if (csvDriverSalGender4.IsValid == false)
                {
                    ddlDriverSalutation4.ChangeValidateEffect(true);
                }
                else
                {
                    ddlDriverSalutation4.ChangeValidateEffect(false);
                }
            }
        }
        else
        {
            ddlDriverSalutation4.ChangeValidateEffect(false);
        }

        //Type of Indentification
        ddlDriverIdType4.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlDriverIdNumber4.ChangeValidationEffectServerSide(strValidationGroup);

        //Driver 5 **************************************************************
        //Salutation
        ddlDriverSalutation5.ChangeValidationEffectServerSide(strValidationGroup);
        //Name
        if (rfvDriverSurName5.Enabled && rfvDriverSurName5.ValidationGroup == strValidationGroup)
        {
            rfvDriverSurName5.Validate();
            if (rfvDriverSurName5.IsValid == false)
            {
                txtDriverSurName5.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDriverSurName5.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDriverSurName5.ControlStyle.CssClass = "";
        }

        //SalGender
        ddlDriverGender5.ChangeValidationEffectServerSide(strValidationGroup);
        if (csvDriverSalGender5.Enabled && csvDriverSalGender5.ValidationGroup == strValidationGroup)
        {
            if (ddlDriverSalutation5.IsValidRequirement() && ddlDriverGender5.IsValidRequirement())
            {
                csvDriverSalGender5.Validate();
                if (csvDriverSalGender5.IsValid == false)
                {
                    ddlDriverSalutation5.ChangeValidateEffect(true);
                }
                else
                {
                    ddlDriverSalutation5.ChangeValidateEffect(false);
                }
            }
        }
        else
        {
            ddlDriverSalutation5.ChangeValidateEffect(false);
        }

        //Type of Indentification
        ddlDriverIdType5.ChangeValidationEffectServerSide(strValidationGroup);

        //Id Number
        ddlDriverIdNumber5.ChangeValidationEffectServerSide(strValidationGroup);
        #endregion

    }

    private void ChangeValidationEffectServerSideSave(string strValidationGroup)
    {
        #region Proposal Details
        //Name
        if (rfvNameSave.Enabled && rfvNameSave.ValidationGroup == strValidationGroup)
        {
            rfvNameSave.Validate();
            if (rfvNameSave.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }

        if (revNameSave.Enabled && revNameSave.ValidationGroup == strValidationGroup)
        {
            if (rfvNameSave.IsValid)
            {
                revNameSave.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "";
        }
        //Postal Code
        if (rfvPostCode.Enabled && rfvPostCode.ValidationGroup == strValidationGroup)
        {
            rfvPostCode.Validate();
            if (rfvPostCode.IsValid == false)
            {
                txtPostCode.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPostCode.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        if (revPostCode.Enabled && revPostCode.ValidationGroup == strValidationGroup)
        {
            if (rfvPostCode.IsValid)
            {
                revPostCode.Validate();
                if (revPostCode.IsValid == false)
                {
                    txtPostCode.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtPostCode.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "";
        }

        //Unit No
        if (rfvUnit1Save.Enabled && rfvUnit1Save.ValidationGroup == strValidationGroup)
        {
            rfvUnit1Save.Validate();
            if (rfvUnit1Save.IsValid == false)
            {
                txtUnit1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit1.ControlStyle.CssClass = "";
        }

        //Home No
        if (rfvUnit2Save.Enabled && rfvUnit2Save.ValidationGroup == strValidationGroup)
        {
            rfvUnit2Save.Validate();
            if (rfvUnit2Save.IsValid == false)
            {
                txtUnit2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtUnit2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtUnit2.ControlStyle.CssClass = "";
        }

        //Address
        if (rfvAddressSave.Enabled && rfvAddressSave.ValidationGroup == strValidationGroup)
        {
            rfvAddressSave.Validate();
            if (rfvAddressSave.IsValid == false)
            {
                txtAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtAddress.ControlStyle.CssClass = "";
        }

       

        //Applicant's Contact Number
        txtContactNo.ChangeValidationEffectServerSide(strValidationGroup);

        //Applicant's NRIC Number
        ddlIdNumber.ChangeValidationEffectServerSide(strValidationGroup);

        //Applicant's Nationality
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Purticulas of Vehicle

        //VehicleNo
        if (rfvVehicleNoSave.Enabled && rfvVehicleNoSave.ValidationGroup == strValidationGroup)
        {
            rfvVehicleNoSave.Validate();
            if (rfvVehicleNoSave.IsValid == false)
            {
                txtVehicleNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtVehicleNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtVehicleNo.ControlStyle.CssClass = "";
        }

        //EngineNo
        if (rfvEngineNoSave.Enabled && rfvEngineNoSave.ValidationGroup == strValidationGroup)
        {
            rfvEngineNoSave.Validate();
            if (rfvEngineNoSave.IsValid == false)
            {
                txtEngineNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtEngineNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtEngineNo.ControlStyle.CssClass = "";
        }
        //ChassisNo
        if (rfvChassisNoSave.Enabled && rfvChassisNoSave.ValidationGroup == strValidationGroup)
        {
            rfvChassisNoSave.Validate();
            if (rfvChassisNoSave.IsValid == false)
            {
                txtChassisNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtChassisNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtChassisNo.ControlStyle.CssClass = "";
        }

        //Hire Purchase
        if (rfvHirePurchaseSave.Enabled && rfvHirePurchaseSave.ValidationGroup == strValidationGroup)
        {
            rfvHirePurchaseSave.Validate();
            if (rfvHirePurchaseSave.IsValid == false)
            {
                lblYesHirePurchase.ControlStyle.CssClass = "validationError";
                lblNoHirePurchase.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesHirePurchase.ControlStyle.CssClass = "";
                lblNoHirePurchase.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesHirePurchase.ControlStyle.CssClass = "";
            lblNoHirePurchase.ControlStyle.CssClass = "";
        }
        //HirePurchaseCompany
        if (rfvHirePurchaseCompanySave.Enabled && rfvHirePurchaseCompanySave.ValidationGroup == strValidationGroup)
        {
            rfvHirePurchaseCompanySave.Validate();
            if (rfvHirePurchaseCompanySave.IsValid == false)
            {
                ddlHirePurchaseCompany.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlHirePurchaseCompany.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlHirePurchaseCompany.ControlStyle.CssClass = "";
        }


        //Insurance Company
        if (rfvExistingInsurerNameSave.Enabled && rfvExistingInsurerNameSave.ValidationGroup == strValidationGroup)
        {
            rfvExistingInsurerNameSave.Validate();
            if (rfvExistingInsurerNameSave.IsValid == false)
            {
                ddlExistingInsurerName.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlExistingInsurerName.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlExistingInsurerName.ControlStyle.CssClass = "";
        }

        //Insurance Policy No
        if (rfvInsPolicyNoSave.Enabled && rfvInsPolicyNoSave.ValidationGroup == strValidationGroup)
        {
            rfvInsPolicyNoSave.Validate();
            if (rfvInsPolicyNoSave.IsValid == false)
            {
                txtInsPolicyNo.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsPolicyNo.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsPolicyNo.ControlStyle.CssClass = "";
        }
        //Insurance Date Of Cancellation
        ddlDOCancellation.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region General Question

        //DermeritPoints
        if (rfvDermeritPointsSave.Enabled && rfvDermeritPointsSave.ValidationGroup == strValidationGroup)
        {
            rfvDermeritPointsSave.Validate();
            if (rfvDermeritPointsSave.IsValid == false)
            {
                lblYesDermeritPoints.ControlStyle.CssClass = "validationError";
                lblNoDermeritPoints.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesDermeritPoints.ControlStyle.CssClass = "";
                lblNoDermeritPoints.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesDermeritPoints.ControlStyle.CssClass = "";
            lblNoDermeritPoints.ControlStyle.CssClass = "";
        }
        //Drivername
        if (rfvDrivername1Save.Enabled && rfvDrivername1Save.ValidationGroup == strValidationGroup)
        {
            rfvDrivername1Save.Validate();
            if (rfvDrivername1Save.IsValid == false)
            {
                txtDrivername1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtDrivername1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtDrivername1.ControlStyle.CssClass = "";
        }
        //Totalpoints
        if (rfvTotalpoints1Save.Enabled && rfvTotalpoints1Save.ValidationGroup == strValidationGroup)
        {
            rfvTotalpoints1Save.Validate();
            if (rfvTotalpoints1Save.IsValid == false)
            {
                txtTotalpoints1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtTotalpoints1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtTotalpoints1.ControlStyle.CssClass = "";
        }

        //Physicalimpairment
        if (rfvPhysicalimpairmentSave.Enabled && rfvPhysicalimpairmentSave.ValidationGroup == strValidationGroup)
        {
            rfvPhysicalimpairmentSave.Validate();
            if (rfvPhysicalimpairmentSave.IsValid == false)
            {
                lblYesPhysicalimpairment.ControlStyle.CssClass = "validationError";
                lblNoPhysicalimpairment.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesPhysicalimpairment.ControlStyle.CssClass = "";
                lblNoPhysicalimpairment.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesPhysicalimpairment.ControlStyle.CssClass = "";
            lblNoPhysicalimpairment.ControlStyle.CssClass = "";
        }
        //Physicalimpairment Reason
        if (rfvPIReasonSave.Enabled && rfvPIReasonSave.ValidationGroup == strValidationGroup)
        {
            rfvPIReasonSave.Validate();
            if (rfvPIReasonSave.IsValid == false)
            {
                txtPIReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtPIReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtPIReason.ControlStyle.CssClass = "";
        }

        //Insurance Terminated Reason
        if (rfvITReasonSave.Enabled && rfvITReasonSave.ValidationGroup == strValidationGroup)
        {
            rfvITReasonSave.Validate();
            if (rfvITReasonSave.IsValid == false)
            {
                txtITReason.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtITReason.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtITReason.ControlStyle.CssClass = "";
        }

        //Insurance Terminated
        if (rfvInsuranceterminatedSave.Enabled && rfvInsuranceterminatedSave.ValidationGroup == strValidationGroup)
        {
            rfvInsuranceterminatedSave.Validate();
            if (rfvInsuranceterminatedSave.IsValid == false)
            {
                lblYesInsuranceterminated.ControlStyle.CssClass = "validationError";
                lblNoInsuranceterminated.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblYesInsuranceterminated.ControlStyle.CssClass = "";
                lblNoInsuranceterminated.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblYesInsuranceterminated.ControlStyle.CssClass = "";
            lblNoInsuranceterminated.ControlStyle.CssClass = "";
        }

        #endregion
    }

    protected void CheckDriverSalGenderValid1(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlDriverSalutation1.GetSalutation();
        string _gender = ddlDriverGender1.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckDriverSalGenderValid2(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlDriverSalutation2.GetSalutation();
        string _gender = ddlDriverGender2.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckDriverSalGenderValid3(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlDriverSalutation3.GetSalutation();
        string _gender = ddlDriverGender3.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckDriverSalGenderValid4(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlDriverSalutation4.GetSalutation();
        string _gender = ddlDriverGender4.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckDriverSalGenderValid5(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlDriverSalutation5.GetSalutation();
        string _gender = ddlDriverGender5.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }

    private void EnableDriverPanels()
    {
        if (txtDriverCount.Text.Trim() == "0")
        {
            pnlDriverDetails.Visible = false;
            pnlDriver1.Visible = false;
            pnlDriver2.Visible = false;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(false);
            ValidateDriver2(false);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "1")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = false;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(false);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "2")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = false;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(false);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "3")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = false;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(false);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "4")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = true;
            pnlDriver5.Visible = false;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(true);
            ValidateDriver5(false);
        }
        else if (txtDriverCount.Text.Trim() == "5")
        {
            pnlDriverDetails.Visible = true;
            pnlDriver1.Visible = true;
            pnlDriver2.Visible = true;
            pnlDriver3.Visible = true;
            pnlDriver4.Visible = true;
            pnlDriver5.Visible = true;

            ValidateDriver1(true);
            ValidateDriver2(true);
            ValidateDriver3(true);
            ValidateDriver4(true);
            ValidateDriver5(true);
        }
    }

    private void ValidateDriver1(bool OnOff)
    {
        rfvDriverSurName1.Enabled = OnOff;
        ddlDriverSalutation1.IsEnableValidation(OnOff);
        ddlDriverGender1.IsEnableValidation(OnOff);
        ddlDriverIdType1.IsEnableValidation(OnOff);
        ddlDriverIdNumber1.IsEnableValidation(OnOff);
        csvDriverSalGender1.Enabled = OnOff;
    }

    private void ValidateDriver2(bool OnOff)
    {
        rfvDriverSurName2.Enabled = OnOff;
        ddlDriverSalutation2.IsEnableValidation(OnOff);
        ddlDriverGender2.IsEnableValidation(OnOff);
        ddlDriverIdType2.IsEnableValidation(OnOff);
        ddlDriverIdNumber2.IsEnableValidation(OnOff);
        csvDriverSalGender2.Enabled = OnOff;
    }

    private void ValidateDriver3(bool OnOff)
    {
        rfvDriverSurName3.Enabled = OnOff;
        ddlDriverSalutation3.IsEnableValidation(OnOff);
        ddlDriverGender3.IsEnableValidation(OnOff);
        ddlDriverIdType3.IsEnableValidation(OnOff);
        ddlDriverIdNumber3.IsEnableValidation(OnOff);
        csvDriverSalGender3.Enabled = OnOff;
    }

    private void ValidateDriver4(bool OnOff)
    {
        rfvDriverSurName4.Enabled = OnOff;
        ddlDriverSalutation4.IsEnableValidation(OnOff);
        ddlDriverGender4.IsEnableValidation(OnOff);
        ddlDriverIdType4.IsEnableValidation(OnOff);
        ddlDriverIdNumber4.IsEnableValidation(OnOff);
        csvDriverSalGender4.Enabled = OnOff;
    }

    private void ValidateDriver5(bool OnOff)
    {
        rfvDriverSurName5.Enabled = OnOff;
        ddlDriverSalutation5.IsEnableValidation(OnOff);
        ddlDriverGender5.IsEnableValidation(OnOff);
        ddlDriverIdType5.IsEnableValidation(OnOff);
        ddlDriverIdNumber5.IsEnableValidation(OnOff);
        csvDriverSalGender5.Enabled = OnOff;
    }

    protected void GetNCDProtection()
    {
        //if ((inputNCD.Value == "40" || inputNCD.Value == "50") && lblAnyclaim.Text == "No")
        if (lblCarId.Text != string.Empty && lblCustomerId.Text != string.Empty
            && lblCarResultId.Text != string.Empty && lblProviderCompanyId.Text != string.Empty)
        {
            _CarId = Convert.ToInt64(lblCarId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
            _CXCTypeId = Convert.ToInt64(lblCarResultId.Text);
            _ProviderId = Convert.ToInt64(lblProviderCompanyId.Text);
        }
        else if (Session[General.CarId] != null && Session[General.UserId] != null &&
            Session[General.CarResultId] != null && Session[General.ProviderCompanyId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CarId].ToString());
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            _CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
            _ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
        }

        if (inputCurrentNCD.Value == "50" && lblAnyclaim.Text == "No")
        {
            lblPremiumBeforeNCDPro.Text = lblPremiums.Text;

            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable();

            string _spName = "[sprocCarInsuranceTempResultSelectItemSelectSingleItem]";
            SortedList _sPara = new SortedList();
            _sPara.Add("@CECarId", _CarId);
            _sPara.Add("@CarResultId", _CXCTypeId);
            _sPara.Add("@RefCEUserId", _UserId);
            _sPara.Add("@ProviderCompanyId", _ProviderId);

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);

            if (_dtResult.Rows.Count > 0)
            {
                lblPremiumAfterNCDPro.Text = String.Format("${0:f}", float.Parse(_dtResult.Rows[0]["Finfo1"].ToString()));
                lblPremiumAfterNCDProNoFormat.Text = String.Format("{0:f}", float.Parse(_dtResult.Rows[0]["Finfo1"].ToString()));
            }
        }
    }

    //protected void SetNewPremium()
    //{
    //    if ((inputNCD.Value == "40" || inputNCD.Value == "50") && lblAnyclaim.Text == "No")
    //    {

    //        lblPremiumBeforeNCDPro.Text = lblPremiums.Text;

    //        Int64 iCeCarId = Convert.ToInt64(Session[General.CarId].ToString());
    //        Int64 iRefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());

    //        CarInsuranceDB _carinsdb = new CarInsuranceDB();
    //        _carinsdb.CalculationEtiqaNCDProtect(iCeCarId, iRefCEUserId, true);


    //        //sets the new premium
    //        DataTable _dtResult = new DataTable();

    //        _dtResult = _carinsdb.GetsNewCalculationPerProvider(iCeCarId, iRefCEUserId, 30); //etiqa

    //        if (_dtResult.Rows.Count > 0)
    //        {
    //            float fPremium = 0;
    //            if (float.TryParse(_dtResult.Rows[0]["AnnualPremium"].ToString(), out fPremium))
    //            {
    //                lblPremiumAfterNCDPro.Text = String.Format("${0:f}", fPremium);
    //                Session[General.CarResultId] = _dtResult.Rows[0]["CITempResultId"].ToString();
    //            }

    //        }
    //    }
    //}

    //protected void SetsFinalPremium()
    //{
    //    if ((inputNCD.Value == "40" || inputNCD.Value == "50") && lblAnyclaim.Text == "No")
    //    {

    //        if (rdoNo.Checked == true && rdoYes.Checked == false)
    //        {
    //            CarInsuranceDB _carinsdb = new CarInsuranceDB();
    //            Int64 iCeCarId = Convert.ToInt64(Session[General.CarId].ToString());
    //            Int64 iRefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());

    //            _carinsdb.CalculationEtiqaNCDProtect(iCeCarId, iRefCEUserId, false);


    //        }
    //    }

    //}

    protected void csvVehicleNoValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtVehicleNoValid.Text = "";
        txtVehicleNoValid.Text = "valid";
        string _VehicleNo = txtVehicleNo.Text.Trim();
        string _FirstLetter = _VehicleNo.Substring(0, 1);
        string _blockVal = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BlockedVehicleChar");
        string[] _BlockedVehicleChar = _blockVal.Split(',');
        args.IsValid = true;
        for (int i = 0; i < _BlockedVehicleChar.Length; i++)
        {
            if (_FirstLetter.ToUpper() == _BlockedVehicleChar[i].ToString())
            {
                args.IsValid = false;
            }
        }
    }

    public string GetOrderNumber()
    {
        Int64 _orderserialno = 0;
        string _result, _orderno, _serialno;
        _result = ""; _orderno = ""; _serialno = "";
        MyDatabase _db = new MyDatabase();
        string _firstno = CE.Global.General.GetUTCDateTime().Year + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");

        if (Session[General.UserId] != null && Session[General.CarId] != null)
        {
            _CarId = Convert.ToInt64(Session[CE.Global.General.CarId].ToString());
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else if (Request.Params["carid"] != null && Request.Params["customerid"] != null)
        {
            _CarId = Convert.ToInt64(lblCarId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
        }


        _result = _firstno + _CarId.ToString("000000");
        string strSql = "SELECT TOP 1 OrderSerialNo FROM tblCarMoreDetail_Etiqa WHERE OrderNo IS NOT NULL ORDER BY OrderSerialNo DESC";
        DataSet _dsResult = new DataSet();
        _dsResult = null;
        _dsResult = _db.GetDataSet(strSql);
        if (_dsResult != null && _dsResult.Tables[0].Rows.Count > 0)
        {
            _orderserialno = Convert.ToInt64(_dsResult.Tables[0].Rows[0][0].ToString());
            _orderserialno = _orderserialno + 1;
            _serialno = _orderserialno.ToString("000000");
        }
        else
        {
            _orderserialno = 1;
            _serialno = _orderserialno.ToString("000000");
        }

        //if (_serialno.Length == 1)
        //{
        //    _serialno = "00000" + _serialno;
        //}
        //else if (_serialno.Length == 2)
        //{
        //    _serialno = "0000" + _serialno;
        //}
        //else if (_serialno.Length == 3)
        //{
        //    _serialno = "000" + _serialno;
        //}
        //else if (_serialno.Length == 4)
        //{
        //    _serialno = "00" + _serialno;
        //}
        //else if (_serialno.Length == 5)
        //{
        //    _serialno = "0" + _serialno;
        //}
        _result += _serialno + "," + _orderserialno.ToString();
        return _result;
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    private bool CheckCarQuoteUpdateStatus()
    {
        bool _retValue = false;
        CarInsuranceCheckDB _carcheck = new CarInsuranceCheckDB();
        Int64 _checkResult = _carcheck.CheckUpdateStatus(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()), Convert.ToInt64(Session[General.CarResultId].ToString()), Convert.ToInt64(Session[General.UserId].ToString()), Convert.ToInt64(Session[General.CarId].ToString()));
        if (_checkResult > 0)
        {
            _retValue = true;
        }
        else
        {
            _retValue = false;
        }

        return _retValue;
    }
}
